generating random strings of letters?

cirthix

Diamond Member
Aug 28, 2004
3,616
1
76
ah, decided to go not-so-random hehe. I just typed sentences without spaces and hit enter every three letters. the grader might get a kick out of it (just data showing that a program works) :p
 

jjones

Lifer
Oct 9, 2001
15,424
2
0
function newRandom($len) {
$var = "";
$key = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$i = 0;
while ($i < $len) {
$char = substr($key, mt_rand(0, strlen($key)-1), 1);
if (!strstr($var, $char)) {
$var.= $char;
$i++;
}
}
return $var;
}

for($i=0; $i<60; $i++) {
print newRandom(3).'<br />';
}

Variation on a random password generator I use. This will run 60 random combinations of 3 letter length and simple modification will run 100 or any number you want.