Bug #60543 [Opn->Dup]: mt_rand() only reliable when ($max - $min) <= mt_getrandmax ()

From: Date: Sat, 15 Aug 2015 10:22:55 +0000
Subject: Bug #60543 [Opn->Dup]: mt_rand() only reliable when ($max - $min) <= mt_getrandmax ()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195225@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60543&edit=1 ID: 60543 Updated by: cmb@php.net Reported by: daniel at danielnorton dot com Summary: mt_rand() only reliable when ($max - $min) <= mt_getrandmax () -Status: Open +Status: Duplicate Type: Bug Package: Math related Operating System: Windows PHP Version: 5.3.8 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This issue has the same cause as bug #60543. As the other ticket is already being worked on (PR #1416), I'm marking this one as duplicate. Previous Comments: ------------------------------------------------------------------------ [2015-08-15 10:22:53] cmb@php.net This issue has the same cause as bug #60543. As the other ticket is already being worked on (PR #1416), I'm marking this one as duplicate. ------------------------------------------------------------------------ [2014-07-31 04:01:12] datibbaw@php.net Can't test this on Windows, but according to 3v4l it can't be reproduced in any of the versions: http://3v4l.org/anJ6F ------------------------------------------------------------------------ [2011-12-16 07:14:09] daniel at danielnorton dot com I suggest changing the title of this to "mt_rand() only reliable when ($max - $min) <= mt_getrandmax ()". ------------------------------------------------------------------------ [2011-12-16 06:18:19] daniel at danielnorton dot com The problem does not appear if ($max - $min) <= PHP_INT_MAX. Perhaps this is a documentation problem and the solution might simply be to specify that ($max - $min) must be less than mt_getrandmax()? ------------------------------------------------------------------------ [2011-12-16 05:38:22] daniel at danielnorton dot com In a 64-bit environment, although documented to be limited to mt_getrandmax() (which is 0x7FFFFFFF in my environment), for the purposes of diagnosis, the following is notable: **1) The problem does not seem to surface when the absolute value of both the $min and $max is within (PHP_INT_MAX/2)-1 (0x3FFFFFFFFFFFFFFF). **2) The oft-repeated value is always $min & PHP_INT_MAX, which always yields a positive integer. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=60543 -- Edit this bug report at https://bugs.php.net/bug.php?id=60543&edit=1

« previous php.bugs (#195225) next »