adam84 Posted January 9, 2008 Share Posted January 9, 2008 function gen_number( $length ){ $time = time(); srand(date("s")); $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $code = ""; while(strlen($code)<$length) $code .= substr($possible_charactors, rand()%(strlen($possible_charactors)),1); return $code; } function temp(){ for($i = 0; $i < 5; $i++) echo gen_number( 5 ) . "<BR>"; } I keep getting the same number all 5 times??!?!?!??!?! what should i do... thanks Quote Link to comment https://forums.phpfreaks.com/topic/85127-solved-random-number-issue/ Share on other sites More sharing options...
Ken2k7 Posted January 9, 2008 Share Posted January 9, 2008 Try: <?php function gen_number( $length, $rand ){ $time = time(); srand(date("s")); $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $code = ""; while(strlen($code)<$length) $code .= substr($possible_charactors, $rand%(strlen($possible_charactors)),1); return $code; } function temp(){ for($i = 0; $i < 5; $i++) echo gen_number( 5 , rand() ) . "<BR>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85127-solved-random-number-issue/#findComment-434250 Share on other sites More sharing options...
adam84 Posted January 9, 2008 Author Share Posted January 9, 2008 no dice Quote Link to comment https://forums.phpfreaks.com/topic/85127-solved-random-number-issue/#findComment-434259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.