RE: [PHP] random numbers
| From: | Jon Haworth | Date: | Tue, 12 Nov 2002 09:40:07 +0000 |
| Subject: | RE: [PHP] random numbers | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-123950@lists.php.net to get a copy of this message | ||
Hi Tamas,
> /* srand is not important since php v>=4.2.0 */
> $numbers = range (1,90);
> $x = array_rand ($numbers, 5);
> foreach ($x as $v) echo "{$numbers[$v]} ";
>
> It works fine, except the first query: php may restart
> the random numbers, if it is not used for some seconds.
I'm not sure how to solve this, but I'm curious as to why you don't want to
use mt_rand:
<?php
for ($i=1; $i<=6; $i++)
$x[] = mt_rand(1, 90);
foreach ($x as $current)
echo $current. "<br />";
?>
You still get an array at the end of it, which seems to be what you're
after.
Cheers
Jon