this a function i use to generate random passwords, feel free to use
it:
function newPassword($length) {
$password = '';
$possible = '123456789abcdefghjkmnpqrtuvwxyz123456789';
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
return $password;
}
if you wanted to generate random alphanumeric numbers without
specifying a string of possible combinations you could always use:
chr() -
http://www.php.net/chr
rand() -
http://www.php.net/rand
and an ASCII table -
http://www.asciitable.com/
so you'd be set up like this:
1) use a loop to control the length (like above)
2) generate a random number between the ASCII intervals you want (see
the ASCII Table) using rand()
3) convert the number to an ASCII character using char() and
concatenate it to your random number variable
-Alex