Hi Yasuo,
Some times ago I mailed my idea about refactoring random number
generator API with min BC breaks but I didn't create an RFC right now.
see http://marc.info/?l=php-internals&m=137772363015217
Marc
On 16.07.2014 07:13, Yasuo Ohgaki wrote:
Hi all,
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?
--
Yasuo Ohgaki
yohg...@ohgaki.net
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php