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





Generate Your Wu-Name

Created: 1999-11-16

PHP Script to Generate Wu-Name
The PHP script Generate Your Wu-Name generates a random name based of an adjective and a noun an example is my Wu-Name: Drunken Conqueror.

The PHP script uses two plain text files, one that holds all of the adjectives and the other 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.

So next all that is needed is to randomly pick elements from these arrays. However, I don't want this to be totally random because your Wu-Name should not change each time you enter it in. Thus, I'll start the random number generator with a seed number, which will be based on the name entered. Using the PHP function srand(seed_number), which works just likes Perl's function, and generates a random number.

Generating 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;
}

Setting up and Picking from Arrays
Here's 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 another name generator which basically just switches out the adjective files.

Download 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-2008. astonishinc.com   All Rights Reserved.