Re: rand() function

From: Date: Fri, 07 Jul 2000 16:05:36 +0000
Subject: Re: rand() function
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-5399@lists.php.net to get a copy of this message
nevermind, I found the code for the mt_rand() function and that's quite over my head, so I'm assuming rand() is as well, thanks. Ed ""Ed Vul"" <edv@whitepj.com> wrote in message news:8k4ukt$8cu$1@toye.php.net... > Yup, thanks guys, that was my problem. I completely looked over the srand() > part in the manual. > One more question though: > What does rand() do to the seed? or are the algorithms or whatever it uses > way over my head? > Thanks > Ed > > "Kris Dahl" <krislists@toolhouse.com> wrote in message > news:B58A797A.8A85%krislists@toolhouse.com... > > on 7/6/00 5:36 PM, David VanHorn at dvanhorn@cedar.net wrote: > > > > > Shouldn't you seed the random generator? > > > > > > Here's what I use to generate random cookies. So far, they look pretty > > > daggone random. > > > > > > srand(date("s")); > > > > I don't think a seed of date("s") is going to give him the level of > > precision that is necessary for a recursively generated random number. > > > > I.e. if it is executed several times in one second (as a loop like this > > would be) it would do exactly what it is doing now. I believe that in PHP > > rand seeds itself with the date function if you don't seed it yourself > > (other wise it would always return the same 'random' number)... so I would > > wager that it would do the exact same thing. > > > > Try seeding it with something like > > srand((double)microtime()*1000000); > > which is actually what they suggest in the PHP manual. > > > > -k > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#5399) next »