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