#22988 [Opn->Ana]: I'm feeling lucky - rand() bug
| From: | pollita@php.net | Date: | Mon, 31 Mar 2003 21:22:49 +0000 |
| Subject: | #22988 [Opn->Ana]: I'm feeling lucky - rand() bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-36852@lists.php.net to get a copy of this message | ||
ID: 22988
Updated by: pollita@php.net
Reported By: vakmajom at freemail dot hu
-Status: Open
+Status: Analyzed
Bug Type: Math related
Operating System: Windows 2000
PHP Version: 4.3.2RC1
New Comment:
This is being caused by a carryover (2147483647 + 1 == -2147483648).
The short answer is: "If it hurts, don't do it!"
Of course that's not a proper answer. The API Macro could probably use
some tweaking...
Previous Comments:
------------------------------------------------------------------------
[2003-03-31 12:36:52] vakmajom at freemail dot hu
The function rand() always returns an even number!
This bug appears when the parameters of rand() are near to the limits
of int (i.e. 2147483647)
Example:
<?php
echo(rand(1, 2147483647));
?>
Result: always an even number.
I'm using Apache 2.0.44 with PHP4.3.2RC1 (original Win32 binary) as an
apache module.
Tests with different systems:
Maybe this is a Windows bug, it still exists in Windows .Net server
build 3718 with PHP 4.3.0 RC3
But everything is fine on a unix system with PHP 4.1.0
Strange... :))
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22988&edit=1