Doc #60559 [Opn->Csd]: mt_rand() backward incompatibility

From: Date: Thu, 15 Nov 2012 17:48:44 +0000
Subject: Doc #60559 [Opn->Csd]: mt_rand() backward incompatibility
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9159@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60559&edit=1

 ID:                 60559
 Updated by:         googleguy@php.net
 Reported by:        kartyl at gmail dot com
 Summary:            mt_rand() backward incompatibility
-Status:             Open
+Status:             Closed
 Type:               Documentation Problem
 Package:            *Math Functions
 Operating System:   Linux
 PHP Version:        5.3.8
-Assigned To:        
+Assigned To:        googleguy
 Block user comment: N
 Private report:     N

 New Comment:

The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2012-05-14 09:36:56] nicolas dot giraud at actiane dot com

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...

------------------------------------------------------------------------
[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)

« previous php.doc.bugs (#9159) next »