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
yohgaki@ohgaki.net
Yasuo Ohgaki wrote (on 16/07/2014):
The only BC issue I can think of is game that expects the same pseudo
random sequences. These apps may usemt_srand()
to get fixed random
sequences and adjust their apps if it is needed. This is acceptable BC
for new releases. IMO.
Do you propose making rand()
a synonym for mt_rand()
? If so, wouldn't it
make sense for srand()
to become a synonym for mt_srand()
?
Or are you saying that there are functions other than rand()
which can
currently be seeded by srand()
, and these would be affected by
mt_srand()
instead? If so, that seems like a pretty subtle change to
document and publicise.
Do you propose making
rand()
a synonym formt_rand()
? If so, wouldn't it make sense forsrand()
to become a synonym formt_srand()
?
Whether that’s what Yasuo proposes or not, I’d like to see this. It’s rather silly that rand()
isn’t the proper one, and that mt_rand()
is. We could always rename rand()
to legacy_rand() or something.
Andrea Faulds
http://ajf.me/
Hi,
Do you propose making
rand()
a synonym formt_rand()
? If so, wouldn't it
make sense forsrand()
to become a synonym formt_srand()
?Whether that’s what Yasuo proposes or not, I’d like to see this. It’s
rather silly thatrand()
isn’t the proper one, and thatmt_rand()
is. We
could always renamerand()
to legacy_rand() or something.
I wasn't intended to use MT rand for rand()
as the bug report suggests (
https://bugs.php.net/bug.php?id=66718)
Having mt_shuffle(), mt_whatever() would not be a good idea. IMO.
Making MT rand the default everywhere is valid choice. Almost all codes
that use rand()
/mt_rand() expect
true randomness even if they are not.
I'll add rand()
rename option for upcoming RFC.
rand()
to lagacy_rand()/rand_legacy()/rand_system(), perhaps? The name can
be any.
Suggestions are appreciated.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
I'll add
rand()
rename option for upcoming RFC.
rand()
to lagacy_rand()/rand_legacy()/rand_system(), perhaps? The name can be any.
Suggestions are appreciated.
IIRC isn’t rand()
implemented using the C function? In that case, c_rand() perhaps?
Andrea Faulds
http://ajf.me/
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 usemt_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
yohgaki@ohgaki.net
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.
I have mixed feelings about that.
What did change since our last discussions? What are the benefits to
do it now? Also I really do no think it is worse the effort and the
addition to do it in 5.x. Yes, there are still apps out there relying
on rand only for areas where it should not be used, but how is it our
problem? I mean: the documentation is clear, have been updated and
clarified many times.
I'd rather focus on doing one set of APIs for RNG for php6 and leave
that untouch for now.
Cheers,
Pierre
@pierrejoye | http://www.libgd.org
Hi Pierre,
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.I have mixed feelings about that.
What did change since our last discussions? What are the benefits to
do it now? Also I really do no think it is worse the effort and the
addition to do it in 5.x. Yes, there are still apps out there relying
on rand only for areas where it should not be used, but how is it our
problem? I mean: the documentation is clear, have been updated and
clarified many times.I'd rather focus on doing one set of APIs for RNG for php6 and leave
that untouch for now.
Would like me to address RNG? It's ok for me.
This is not a critical issue. I don't mind at all to postpone this change.
I'll wait to finish RNG implementation, then decide what we will do for
this.
I would like to finish session related changes first. (Most critical issue
will be
addressed in session-ng, though)
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
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
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_5These 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 usemt_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
yohgaki@ohgaki.net