...

View Full Version : random



HormonX
10-28-2002, 08:37 PM
Hello,

can someone sugest me a way to create a random sequence of letters and numbers ? I have a script that does that .. but it's very incosistent. What's happening is ... one time it will create a 20 caracter string, but next time it will only create a 5 caracter string. here it is below.




$length = 20;// set this to legth of the random word/number
$p = "0wxVWvKH678FSbkUXIJ".
"aefglm9ijD5yGupqrs".
"AE3cdLMNOPhtz124BYCZQRnoT";
$r1 = substr($p, (rand() % strlen($p)), $length);
$string = $r1;



any sugestions ?

HormonX

Robbie
10-28-2002, 09:16 PM
I'm currently using this for random pieces of text and letters.
works great for me...



function GeneratePWD($length){
$letters = array(
'a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x',
'y','z',
'A','B','C','D','E','F','G','H',
'I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X',
'Y','Z',
'0','1','2','3','4','5','6','7',
'8','9');
srand((double) microtime() * 1000000);
for ($c = 0; $c < $length; $c++)
$password .= $letters[rand(0,count($letters))];
return $password;
}

HormonX
10-29-2002, 01:45 AM
thanx robbie for that tip.

HormonX

Nightfire
10-29-2002, 03:50 AM
srand((double)microtime()*1000000);
$ID = substr(md5(rand(0,32000)), 0, 10);
$r = rand(0,1);
if ($r == "0") {
$ID;
} else {
$ID = strtoupper($ID);
}

$password = $ID;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum