Demonic Posted May 3, 2008 Share Posted May 3, 2008 Does Seeding the random function make the random number not repeat? Why do you seed the rand() function? function make_password() { $pass = ""; $chars = array( "1","2","3","4","5","6","7","8","9","0", "a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J", "k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T", "u","U","v","V","w","W","x","X","y","Y","z","Z"); $count = count($chars) - 1; srand((double)microtime()*1000000); for($i = 0; $i < 8; $i++) { $pass .= $chars[rand(0, $count)]; } return($pass); } Example function from ipb 1.3 Link to comment https://forums.phpfreaks.com/topic/103955-solved-seeding-random-quotrandquot-function/ Share on other sites More sharing options...
redarrow Posted May 3, 2008 Share Posted May 3, 2008 all the function does is make a random 8 charecter/number and ads the varable $pass to the beging........... <?php $pass="redarrow"; function pass($pass) { $chars = array( "1","2","3","4","5","6","7","8","9","0", "a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J", "k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T", "u","U","v","V","w","W","x","X","y","Y","z","Z"); $count = count($chars) - 1; srand((double)microtime()*1000000); for($i = 0; $i < 8; $i++) { $pass .= $chars[rand(0, $count)]; } return($pass); } echo pass($pass) ?> Link to comment https://forums.phpfreaks.com/topic/103955-solved-seeding-random-quotrandquot-function/#findComment-532198 Share on other sites More sharing options...
hitman6003 Posted May 3, 2008 Share Posted May 3, 2008 As the php manual states: Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. http://www.php.net/srand Link to comment https://forums.phpfreaks.com/topic/103955-solved-seeding-random-quotrandquot-function/#findComment-532199 Share on other sites More sharing options...
AndyB Posted May 3, 2008 Share Posted May 3, 2008 To amplify ... google triumphs http://hudzilla.org/phpwiki/index.php?title=Generating_random_numbers Link to comment https://forums.phpfreaks.com/topic/103955-solved-seeding-random-quotrandquot-function/#findComment-532200 Share on other sites More sharing options...
Demonic Posted May 3, 2008 Author Share Posted May 3, 2008 all the function does is make a random 8 charecter/number and ads the varable $pass to the beging........... I never asked what teh function does, because its quite obvious what it does. Anyways thanks, so seeding random numbers are deprecate. solved.. Link to comment https://forums.phpfreaks.com/topic/103955-solved-seeding-random-quotrandquot-function/#findComment-532201 Share on other sites More sharing options...
redarrow Posted May 3, 2008 Share Posted May 3, 2008 so this example is better then using mt_rand...... dont no <?php $pass="redarrow"; function pass($pass) { $chars = array( "1","2","3","4","5","6","7","8","9","0", "a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J", "k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T", "u","U","v","V","w","W","x","X","y","Y","z","Z"); $count = count($chars) - 1; for($i = 0; $i < 8; $i++) { $pass .= $chars[mt_rand(0, $count)]; } return($pass); } echo pass($pass) ?> Link to comment https://forums.phpfreaks.com/topic/103955-solved-seeding-random-quotrandquot-function/#findComment-532212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.