|
Posted by Iain on 10/13/29 11:28
Thanks for this. This snip is missing from my php manual chm :-( But I still
don't get it...
On the Windows dev box I have php 4.3.3, i.e. after 4.2.0, and on this box
both rand() and mt_rand() only ever give me the max value, i.e.
[mt_]rand(0,2)
only ever yields a 2.
On the Linux hosted service which phpinfo() reports as 4.1.2, i.e. before
4.2.0, I do get random numbers although the first call is always a 2 and
there seems a bias towards 2 (rand_max).
But if I insert your seed as in:
$images = array (
"<img src=\"/images1.jpg\" \">",
"<img src=\"/images2.jpg\" \">",
"<img src=\"/images3.jpg\" \">"
);
mt_srand ((double) microtime() * 1000000);
$picture = $images[mt_rand(0,2)];
print ("$picture");
I do indeed get random pictures!
So thanks for the hint, I just don't get why I need the seed on 4.3.3 but am
happy you pointed me this direction :-)
Many thanks.../Iain
"Oli Filth" <catch@olifilth.co.uk> wrote in message
news:1128345409.246973.172050@o13g2000cwo.googlegroups.com...
> According to the manual (http://php.net/rand):
>
> "As of PHP 4.2.0, there is no need to seed the random number generator
> with srand() or mt_srand() as this is now done automatically."
[Back to original message]
|