I made some change to my code to open a single file.
function get_random_word($min_length, $max_length)
{
$word = "";
$dictionary = ("dict/words/american.2");
$fp = fopen($dictionary, "r");
$size = filesize($dictionary);
// go to random location in dictionary
srand ((double) microtime() * 100000);
$rand_location = rand(0, $size);
fseek($fp, $rand_location);
// get the next whole word of the right length in file
while(strlen($word)< $min_length || strlen($word)>$max_length)
{
if(feof($fp))
fseek($fp, 0); // if at end go to start
$word = fgets($fp, 80); // skip first word
$word = fgets($fp, 80); // potential password
};
$word = trim($word);
return $word;
}
How can I change this so that it opens a random file in the directory "words".