PHP - Can you help me optimize a 'random name generator' script?

  • Thread starter Thread starter sirdufus69
  • Start date Start date
S

sirdufus69

Guest
I am not a programmer but am teaching myself a little bit at a time. The script is not pretty but is functional...I am sure there is a better way to do it than repeating the code 5 times but that's over my head. I will award full points to the person that can help me with the following tasks:

-optimize for speed and proper php coding technique
-generate a list of 5 random names taken from file1 and file2
-important that words don't appear twice in the same list
-when the 'refresh' button is clicked, does the entire page have to be reloaded? would rather just have the list of 5 items reload instead...is this possible?

----

<?
function RandomAdjective($filename) {
$adjective = file($filename) ;
return $adjective[array_rand($adjective)] ;
}
function RandomAdjective2($filename) {
$adjective2 = file($filename) ;
return $adjective2[array_rand($adjective2)] ;
}
function RandomAdjective3($filename) {
$adjective3 = file($filename) ;
return $adjective3[array_rand($adjective3)] ;
}
function RandomAdjective4($filename) {
$adjective4 = file($filename) ;
return $adjective4[array_rand($adjective4)] ;
}
function RandomAdjective5($filename) {
$adjective5 = file($filename) ;
return $adjective5[array_rand($adjective5)] ;
}
function RandomNoun($filename) {
$noun = file($filename) ;
return $noun[array_rand($noun)] ;
}
function RandomNoun2($filename) {
$noun2 = file($filename) ;
return $noun2[array_rand($noun2)] ;
}
function RandomNoun3($filename) {
$noun3 = file($filename) ;
return $noun3[array_rand($noun3)] ;
}
function RandomNoun4($filename) {
$noun4 = file($filename) ;
return $noun4[array_rand($noun4)] ;
}
function RandomNoun5($filename) {
$noun5 = file($filename) ;
return $noun5[array_rand($noun5)] ;
}
$yadjective = RandomAdjective("adjectives.txt");
$ynoun = RandomNoun("nouns.txt");
$yadjective2 = RandomAdjective2("adjectives.txt");
$ynoun2 = RandomNoun2("nouns.txt");
$yadjective3 = RandomAdjective3("djectives.txt");
$ynoun3 = RandomNoun3("nouns.txt");
$yadjective4 = RandomAdjective4("adjectives.txt");
$ynoun4 = RandomNoun4("nouns.txt");
$yadjective5 = RandomAdjective5("adjectives.txt");
$ynoun5 = RandomNoun5("nouns.txt");
echo trim($yadjective) . ($ynoun) ;
echo "<br />";
echo trim($yadjective2) . ($ynoun2) ;
echo "<br />";
echo trim($yadjective3) . ($ynoun3) ;
echo "<br />";
echo trim($yadjective4) . ($ynoun4) ;
echo "<br />";
echo trim($yadjective5) . ($ynoun5) ;
?>

<form><INPUT TYPE="button" VALUE="Reload" onClick='parent.location="javascript:location.reload()"'></form>
 
Back
Top