Re: [RFC] RNG fixes
| From: | Jordi Boggiano | Date: | Wed, 15 Jun 2016 13:04:36 +0000 |
| Subject: | Re: [RFC] RNG fixes | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94006@lists.php.net to get a copy of this message | ||
On 15/06/2016 13:41, Tom Worster wrote:
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.beint mt_rand ( $mode = MT_RAND_COMPAT )int mt_rand ( int $min, int $max, $mode = MT_RAND_COMPAT )MT_RAND_COMPAT = 1MT_RAND_MT19937 = 2A 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.