Re: rand() function

From: Date: Fri, 07 Jul 2000 00:59:23 +0000
Subject: Re: rand() function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-5296@lists.php.net to get a copy of this message
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

« previous php.general (#5296) next »