Hi all, On Sat, Feb 20, 2016 at 10:39 AM, Andrea Faulds <a...@ajf.me> wrote: > > Yasuo Ohgaki wrote: >> >> This should be discussed in internals. >> MT rand being not MT rand is unacceptable. >> This fix must included in released versions. IMHO. >> >> In any case we should provide broken MT rand, we must use INI switch >> or other options. > > > PHP's implementation of the Mersenne Twister algorithm is buggy, so it > doesn't produce the same output as in other languages. But the buggy > algorithm produces sufficiently random sequences of apparently the same > quality as the proper algorithm. So we *could* simply consider this as a > documentation issue if we wanted to. I'm not saying that's the right course > of action, though.
It seems good enough for quick analysis via ent. Note: Ent tests per "byte", not php_uint32. http://www.fourmilab.ch/random/ WITH FIX [yohgaki@dev rand]$ ~/git/oss/php.net/php-src/php-bin -r '$i = 1000000;while($i--) echo pack("I", mt_rand());' | ./ent Entropy = 7.954269 bits per byte. Optimum compression would reduce the size of this 4000000 byte file by 0 percent. Chi square distribution for 4000000 samples is 250901.85, and randomly would exceed this value less than 0.01 percent of the times. Arithmetic mean value of data bytes is 111.4725 (127.5 = random). Monte Carlo value for Pi is 3.486975487 (error 10.99 percent). Serial correlation coefficient is -0.049294 (totally uncorrelated = 0.0). WITHOUT FIX [yohgaki@dev rand]$ php -r '$i = 1000000;while($i--) echo pack("I", mt_rand());' | ./ent Entropy = 7.954382 bits per byte. Optimum compression would reduce the size of this 4000000 byte file by 0 percent. Chi square distribution for 4000000 samples is 250280.94, and randomly would exceed this value less than 0.01 percent of the times. Arithmetic mean value of data bytes is 111.5000 (127.5 = random). Monte Carlo value for Pi is 3.483663484 (error 10.89 percent). Serial correlation coefficient is -0.049192 (totally uncorrelated = 0.0). I'm not sure if this result is good enough to say "It's ok". MT rand has very long cycle and this quick test does not prove it. Did anyone do better analysis? Otherwise, I'm uncomfortable with basic algorithm change. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php