Doc #60559 [Com]: mt_rand() backward incompatibility
Edit report at https://bugs.php.net/bug.php?id=60559&edit=1
ID: 60559
Comment by: nicolas dot giraud at actiane dot com
Reported by: kartyl at gmail dot com
Summary: mt_rand() backward incompatibility
Status: Open
Type: Documentation Problem
Package: *Math Functions
Operating System: Linux
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
It seems this Warning does not appear in PHP 5.3.3:
Test script:
----------------
<?php
echo PHP_VERSION . "\n";
error_reporting(-1);
ini_set('display_errors', 1);
for ($i = 0; $i < 5; $i++) {
var_dump(mt_rand(160, 0));
echo "\n";
}
?>
Result:
---------------
5.3.3-7+squeeze8
int(89)
int(95)
int(134)
int(154)
int(157)
Maybe the warning was added in PHP 5.3.8 and further...
Previous Comments:
------------------------------------------------------------------------
[2011-12-19 10:31:29] kartyl at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/migration53.incompatible
---
It looks like in PHP 5.2 mt_rand($a, $b) returned the value from the range between $a and $b. There
was no the requirement that $b must be greater than $a (checked on PHP 5.2.17).
In PHP 5.3.8 the warning is triggered and boolean false is returned if second parameter is less than
the first.
[19-Dec-2011 11:26:47] PHP Warning: mt_rand(): max(2) is smaller than min(5) in
/mnt/hgfs/data/ciao-php/ciao/test.php on line 6
I haven't noticed this incompatibility in the backward incompatible changes list.
Test script:
---------------
<?php
for ($i = 0; $i < 5; $i++) {
var_dump(mt_rand(160, 0));
echo "\n";
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60559&edit=1
Thread (3 messages)