Hi all,

On Wed, Jul 16, 2014 at 2:13 PM, Yasuo Ohgaki <yohg...@ohgaki.net> wrote:

> There are few places that uses php_rand() currently.
>
> https://bugs.php.net/bug.php?id=66718
>
> http://lxr.php.net/search?q=php_rand&defs=&refs=&path=&hist=&project=PHP_5_5
>
> These functions could use php_mt_rand() instead of php_rand().
>
> php_rand() uses several rand functions
>
> 62PHPAPI long php_rand(TSRMLS_D)
> 63{
> 64    long ret;
> 65
> 66    if (!BG(rand_is_seeded)) {
> 67        php_srand(GENERATE_SEED() TSRMLS_CC);
> 68    }
> 69
> 70#ifdef ZTS
> 71    ret = php_rand_r(&BG(rand_seed));
> 72#else
> 73# if defined(HAVE_RANDOM)
> 74    ret = random();
> 75# elif defined(HAVE_LRAND48)
> 76    ret = lrand48();
> 77# else
> 78    ret = rand();
> 79# endif
> 80#endif
> 81
> 82    return ret;
> 83}
>
> Most systems use random() which has cycle of 16 * ((2^31) - 1),
> while MT rand has 2^19937-1.
>
> php_mt_rand() could be used where php_rand() is used. Unlike php_rand(),
> php_mt_rand() does not check if it is seeded or not. It should be changed
> to check seed status.
>
> The only BC issue I can think of is game that expects the same pseudo
> random sequences. These apps may use mt_srand() to get fixed random
> sequences and adjust their apps if it is needed. This is acceptable BC
> for new releases. IMO.
>
> It would be good idea to support 64bit version of MT on 64bit platforms,
> too.
>
> http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html
>
> Any comments?
>

RFC for this is created.

https://wiki.php.net/rfc/use-php_mt_rand

New rand() function name is TBD. I cannot think of good name, but
I like rand_system(). rand() may stay as it is now also.

Regards,

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

Reply via email to