Bug #70003 [Opn]: mt_rand producing non random values

From: Date: Tue, 07 Jul 2015 10:55:14 +0000
Subject: Bug #70003 [Opn]: mt_rand producing non random values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194171@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70003&edit=1 ID: 70003 Updated by: cmb@php.net Reported by: cjds at live dot com Summary: mt_rand producing non random values Status: Open Type: Bug Package: Math related Operating System: Windows/ Linux 32 bits PHP Version: 5.6Git-2015-07-06 (Git) Block user comment: N Private report: N New Comment: Seems to have the same cause as bug #63174. Previous Comments: ------------------------------------------------------------------------ [2015-07-06 18:47:43] cjds at live dot com Description: ------------ --- From manual page: http://www.php.net/function.mt-rand --- PHPs mt_rand function fails on 32 bit machines. It produces a certain value more than half the time. When the difference between the values are higher than the max_rand value then the system will return a certain value more than half the time. For example in the code given the system returns 1 more than 5000 times while generating 10000 random numbers Test script: --------------- $count=0; for ($i = 0; $i <= 10000; $i++) { $rand=mt_rand(-2147483608,2147483647); if($rand==1){$count++;} } echo('mt_getrandmax()='.mt_getrandmax().' count='.$count); Expected result: ---------------- mt_getrandmax()=2147483647 count=0 Actual result: -------------- mt_getrandmax()=2147483647 count=5034 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70003&edit=1

« previous php.bugs (#194171) next »