Hack Forums
Star Wars Name Generator Website Code - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141)
+---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50)
+---- Thread: Star Wars Name Generator Website Code (/showthread.php?tid=5931416)



Star Wars Name Generator Website Code - deityjake - Jan 19, 2019

Hi guys,

need a starwars name generator HTML Code for a website project for my college. I have no experience with coding so i really need some help if u can just PM me or post a reply. Thanks.


RE: Star Wars Name Generator Website Code - phlex - Jan 19, 2019

(Jan 19, 2019 09:33 AM)deityjake Wrote:  Hi guys,

need a starwars name generator HTML Code for a website project for my college. I have no experience with coding so i really need some help if u can just PM me or post a reply. Thanks.

I will give you an example & you can just fill in the values to make it better :)

PHP
PHP Code

<?php 
$firstnames 
= array("Anakin", "Padme", "Cassian", "Raymus", "Darth", "Sio", "Jar Jar", "Commander", "Count", "Boba");
$lastnames = array("Skywalker", "Amidala", "Andor", "Antilles", "Vader", "Bibble", "Binks", "Bly", "Dooku", "Fett");
$numfirst = count($firstnames);
$numlast = count($lastnames);
$randfirst = rand(0, $numfirst);
$randlast = rand(0, $numlast);
echo 
$randomname = "{$firstnames[$randfirst]} {$lastnames[$randlast]}"; 

JS
Code
var firstnames = ["Anakin", "Padme", "Cassian", "Raymus", "Darth", "Sio", "Jar Jar", "Commander", "Count", "Boba"],
lastnames = ["Skywalker", "Amidala", "Andor", "Antilles", "Vader", "Bibble", "Binks", "Bly", "Dooku", "Fett"],
numfirst = firstnames.length,
numlast = lastnames.length,
randfirst = Math.floor(Math.random() * (numfirst.length)),
randlast = Math.floor(Math.random() * (numlast.length)),
randomname = firstnames[randfirst] + " " + lastnames[randlast]

Both of these examples choose a random first name, a random last name, and combine them.
If you want REAL Star Wars names (example: Jar Jar Binks, never Jar Jar Fett) then you would put the first & last names in one array & just use the random function for the single array :)


RE: Star Wars Name Generator Website Code - realsunjester - Jan 19, 2019

with a better seed..

Code
<?php
//sunjester
$names = ["name", "name2", "name3", "name4", "name5", "name6"];
$seed = explode(' ', microtime());
srand($seed[0]+$seed[1]*1000000);

for($i=0;$i<4;$i++)
{
        echo $names[rand(0,count($names)-1)]."<br/>";
}
?>



RE: Star Wars Name Generator Website Code - Owl - Jan 19, 2019

JS:

Code
const f_names = ['jake', '""deity""'];
const s_names = ['lol', 'rly'];

let name = `${
   s_names[~~(s_names.length * Math.random())]
},  ${
   f_names[~~(f_names.length * Math.random())]
}`;

oops didn't see phlex posted a JS one as well.


RE: Star Wars Name Generator Website Code - deityjake - Jan 20, 2019

Thanks so much man appreciate it bigtime