Hi all,

There is discussion for this commit in github comments.

https://github.com/php/php-src/commit/a0724d30817600540946b41e40f4cfc2a0c30f80#commitcomment-16174204

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.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net


On Thu, Feb 18, 2016 at 8:09 PM, Leigh <le...@php.net> wrote:
> Commit:    a0724d30817600540946b41e40f4cfc2a0c30f80
> Author:    Leigh <le...@php.net>         Thu, 18 Feb 2016 11:09:01 +0000
> Parents:   aa383d633e72d7c9f5e9b0cb4fa75757558cad55
> Branches:  PHP-7.0
>
> Link:       
> http://git.php.net/?p=php-src.git;a=commitdiff;h=a0724d30817600540946b41e40f4cfc2a0c30f80
>
> Log:
> Revert "Fix #71152: mt_rand() returns the different values from original 
> mt19937ar.c"
>
> This reverts commit 6f6bd8ce531636134efd5f669a4e8373fb2e9e51.
>
> `mt_rand()` is seedable with `mt_srand()` which means it can be used to 
> (re)produce specific streams of numbers. All code (no matter how few 
> instances that may be) that previously depended on this behaviour will no 
> longer produce the same results.
>
> This kind of change needs to be discussed before being committed.
>
> Bugs:
> https://bugs.php.net/71152
>
> Changed paths:
>   M  ext/standard/rand.c
>   D  ext/standard/tests/math/mt_rand_value.phpt
>
>
> Diff:
> diff --git a/ext/standard/rand.c b/ext/standard/rand.c
> index bc32f24..2dd05e7 100644
> --- a/ext/standard/rand.c
> +++ b/ext/standard/rand.c
> @@ -146,7 +146,7 @@ PHPAPI zend_long php_rand(void)
>  #define loBits(u)     ((u) & 0x7FFFFFFFU)  /* mask     the highest   bit of 
> u */
>  #define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of 
> v */
>
> -#define twist(m,u,v)  (m ^ (mixBits(u,v)>>1) ^ 
> ((php_uint32)(-(php_int32)(loBit(v))) & 0x9908b0dfU))
> +#define twist(m,u,v)  (m ^ (mixBits(u,v)>>1) ^ 
> ((php_uint32)(-(php_int32)(loBit(u))) & 0x9908b0dfU))
>
>  /* {{{ php_mt_initialize
>   */
> diff --git a/ext/standard/tests/math/mt_rand_value.phpt 
> b/ext/standard/tests/math/mt_rand_value.phpt
> deleted file mode 100644
> index eeb009e..0000000
> --- a/ext/standard/tests/math/mt_rand_value.phpt
> +++ /dev/null
> @@ -1,53 +0,0 @@
> ---TEST--
> -Test mt_rand() - returns the exact same values as mt19937ar.c
> ---FILE--
> -<?php
> -
> -mt_srand(12345678);
> -
> -for ($i=0; $i<16; $i++) {
> -    echo mt_rand().PHP_EOL;
> -}
> -echo PHP_EOL;
> -
> -$x = 0;
> -for ($i=0; $i<1024; $i++) {
> -    $x ^= mt_rand();
> -}
> -echo $x.PHP_EOL;
> -
> -/*
> -excpect values are obtained from original mt19937ar.c as follows:
> -
> -int i, x;
> -init_genrand(12345678);
> -for (i=0; i<16; i++) {
> -    printf("%d\n", genrand_int31());
> -}
> -printf("\n");
> -x = 0;
> -for (i=0; i<1024; i++) {
> -    x ^= genrand_int31();
> -}
> -printf("%d\n", x);
> -*/
> -?>
> ---EXPECTF--
> -527860569
> -1711027313
> -1280820687
> -688176834
> -770499160
> -412773096
> -813703253
> -898651287
> -52508912
> -757323740
> -511765911
> -274407457
> -833082629
> -1923803667
> -1461450755
> -1301698200
> -
> -1612214270
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to