web blazonry web development scripts and tutorials
 
Web blazonry.com
   Home       PHP       Name Generators       Perl       CSS       Javascript       Java       devTips       Resources   

Name Generator Home


Name Generators
  Wu-Name
  U.S. Name
  Baby Name





Wu-Name Name Generator - How It Works

Wu-Name Name Generator creates a random name consisting of an adjective and a noun. For example, my Wu-Name is Drunken Conqueror.

The PHP script uses two plain text files. One file holds all the adjectives. The other consists of all of the nouns. The script reads these files into two arrays. The PHP function file(filename) reads the filename file into an array with each line being an element of the array.

Next, randomly pick an element from each array. However, I don't want this to be totally random because your Wu-Name should not change each time you enter generate it. Thus, I start the random number generator with a seed number, which is based on the name entered. I use the PHP function srand(seed_number) to generate a random number. (This works just like the Perl function.)

How to Generate the Seed Number
To generate the seed number, I take the name submitted and character by character convert it to its ASCII number, using the PHP function ord(chr). This would generate the same name for ab as it would ba, so to avoid that I multiply the ASCII number by its position in the name.

$seed = 0; $s=0; for ($e=1; $e<=$len; $e++) {
$chr = substr($realname,$s,$e);
$seed = $seed + ord($chr)*$e;

$s=$e;
}

How to Set Up and Pick from Arrays
Here is the PHP code for setting up the two arrays and creating the random number:

// set up arrays
$adj_array = file("adjs");
$noun_array = file("nouns");

// start random number with seed
srand($seed);

// get random numbers
$arnd = rand(0,sizeof($adj_array)-1);
$nrnd = rand(0,sizeof($noun_array)-1);

// create name from names and arrays
$wuname = "$adj_array[$arnd] $noun_array[$nrnd]";

 

U.S. Name Generator is based on wu-name name generator script. It basically switches out the adjective files for files consisting of first name and last name and uses a more complex form by adding a drop-down menu to select male or female.

Baby Name Generator is another name generator is based on wu-name name generator script. It switches out the adjective files for files consisting of first name and middle name and uses a more complex form by adding a drop-down menu to select boy or girl.

Get the full script here (wuname.phps)
View Adjective File
View Nouns File

 

Newest Pages
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Source Code for Test Google Ads (PHP)
Most Popular Pages
U.S. Name Generator
Wu Name Generator
Baby Name Generator
Upload and Resize an Image (PHP)
Popup Windows (JavaScript)
How To Install Apache + PHP + MySQL
Simple Web Calendar (PHP)

Least Popular Pages
Image Load-Order (Javascript)
dHTML: Scrolling Layers
iNews Aplet (Java)
ProcLog Search Your Logs (Perl)
 
 

  © 1997-2007. astonishinc.com   All Rights Reserved.