Re: Rand function
| From: | Jason Wong | Date: | Tue, 22 Jan 2002 11:07:57 +0000 |
| Subject: | Re: Rand function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-81516@lists.php.net to get a copy of this message | ||
On Tuesday 22 January 2002 18:52, Sam wrote:
> Hi all,
>
> Can anyone tell me why, when I run this
>
> $number = rand (1,12);
> The only number that ever appears is 5?
> Not really a random number...
You need to seed the random number generator using srand(). Best to read the
online annotated manual as there's some useful info regarding random number
generation.
Remember you only need to call srand() *ONCE* during the lifetime of your php
script. Do NOT call srand() each time you want a random number.
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
/*
Now hatred is by far the longest pleasure;
Men love in haste, but they detest at leisure.
-- George Gordon, Lord Byron, "Don Juan"
*/