On 15/06/2016 13:41, Tom Worster wrote:
int mt_rand ( $mode = MT_RAND_COMPAT )
int mt_rand ( int $min, int $max, $mode = MT_RAND_COMPAT )
MT_RAND_COMPAT = 1
MT_RAND_MT19937 = 2
A PHP user needs to make the right choice of what to use in their
situation. A technical description of the modes would be confusing and
unhelpful to most users. I have no idea how to document this simply,
honestly and accurately, and without jumping to conclusions about
suitability.
This is why I think a compat/correct mode switch doesn't improve PHP.
It's inconsistent with the spirit set out in the preamble of "PHP RFC:
Your Title Here"[1].
[1] https://wiki.php.net/rfc/template
Similarly, the $mode arg allows us to add MT_RAND_XOROSHIRO128_PLUS or
whatever (interesting to some of us, more "modern", perhaps arguably
more "strong" or are otherwise "better") aren't improvements to PHP
unless users are asking for them.
Just a thought here, if the goal is to provide a better interface,
wouldn't it be better to use OO for this? Not because OO is better, but
because it would avoid having problems if two mt_rand-using pieces of
code are executed concurrently.
Something like this:
$gen1 = new SeededRandom(MT_RAND_MT19937, 23);
$gen2 = new SeededRandom(MT_RAND_MT19937, 23);
$gen1->rand(); // or get()? generate()?
$gen1->rand();
$gen2->rand(); // returns the same as the first call as both use seed 23
With the current situation, if you add a library that relies on mt_rand
you can suddenly break your ability to get consistent numbers.
Cheers
--
Jordi Boggiano
@seldaek - http://seld.be
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php