January 2006 Archives

in how to code |

We were talking about these quizzes where you enter your name and it displays silly, sometimes downright rude names. For instance prison bitch name.

I found a lot of scripts around, but this one from Generate your wu-name uses php and is the neatest.

I put it in under delicacies, I think I need some more entries there. Since even delicacies contents are in MT, I created a post that had this code:


<form action="<?=$SCRIPT_NAME?>" method="POST">
<p><b>Enter your Name: </b><br>
<input type="text" name="realname" size=35> &nbsp; &nbsp;
<input type="submit" value="submit">
</p>
</form><br />

<?
if ($REQUEST_METHOD == "POST")
{
$displayname = $realname;
$realname = strtolower($realname);

/*== generate seed number from name submitted ==*/
$len = strlen($realname);
$seed = 0; $s = 0;

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

$s=$e;
}

/*== read in the two files into the arrays ==*/
$adj_array = file("list_one");
$noun_array = file("list_two");

/*== set random seed ==*/
srand($seed);

/*== get the random numbers for each name first/last or adj/noun ==*/
$arnd = rand(0,sizeof($adj_array)-1);
$nrnd = rand(0,sizeof($noun_array)-1);

/*== create name from random numbers ==*/
$wuname = "$adj_array[$arnd] $noun_array[$nrnd]";

print "<p>You are ";
print "<strong> $wuname</strong></p>";
}

?>


list_one and list_two are two text files placed in the same place as the generator page (ie in the archives under the same category) and are lists of adjectives, like: silly, amazing, beautiful, short and nouns like: cow-girl, dancer, slayer, watcher. Make sure to change the file names to take out the .txt extension.

This can be extended to more than 2 descriptors of course. And I can add to the list. It's cute.


delicious  digg  facebook  google  reddit  stumbleupon