Bug #1166: rand() max value is always 1 greater than it should be.
| From: | mike24 at bellsouth dot net | Date: | Sat, 20 Feb 1999 03:18:50 +0000 |
| Subject: | Bug #1166: rand() max value is always 1 greater than it should be. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-4171@lists.php.net to get a copy of this message | ||
From: mike24@bellsouth.net
Operating system: Redhat 5.1 Linux 2.0.35
PHP version: 3.0.6
PHP Bug Type: Misbehaving function
Bug description: rand() max value is always 1 greater than it should be.
rand() always uses a max value 1 greater than inputed.
Consider the following code snippet:
<?php
srand((double)microtime()*1000000);
$number = rand(5, 15);
$echo "$number\n";
?>
$number should contain an integer between 5 and 15. However, this bug causes $number to contain an
integer between 5 and 16.
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net