rand(min, max) always returns min
| From: | Jeff Mainville | Date: | Mon, 15 Dec 2003 21:13:24 +0000 |
| Subject: | rand(min, max) always returns min | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-172760@lists.php.net to get a copy of this message | ||
Howdy,
I've seen this topic posted once before, but without ever reaching a
conclusion. The earlier posting is at
http://marc.theaimsgroup.com/?l=php-general&m=105414659615227&w=3
The problem: rand(min, max) always returns min on some systems.
rand(), mt_rand, and mt_rand(min, max) all work fine.
I've seen this fail on the following systems:
4.3.4/apache2/solaris 8 sparc
4.3.4/apache2/solaris 9 sparc
5.0.0b2/apache2/solaris 9 sparc
But it works on
4.3.0/apache2/win2k
4.3.4/apache2/solaris 8 sparc
All of the systems where it fails have /dev/*random on them.
All of the systems where it works do not have /dev/*random on them.
Code to test:
<?PHP
echo "version " . phpversion() . "<P>";
echo "rand(): " . rand() . "<P>"; // works
echo "rand(1,100): " . rand(1,100) . "<P>"; // fails; always
returns 1
echo "mt_rand(): " . mt_rand() . "<P>"; // works
echo "mt_rand(1,100): " . mt_rand(1,100) . "<P>"; // works
?>
Any insight or pointers as to why this might be failing will be appreciated.
Thanks,
jeff