Re: PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug
| From: | Solar Designer | Date: | Wed, 16 Aug 2017 21:41:55 +0000 |
| Subject: | Re: PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100237@lists.php.net to get a copy of this message | ||
On Wed, Aug 16, 2017 at 10:06:02PM +0200, Nikita Popov wrote:
> I'd suggest to split the 32-bit and 64-bit code codepaths entirely, as the
> interleaved #ifs are somewhat hard to follow. Something like
> https://gist.github.com/nikic/64e7ec58ebb6121d350fb80927a65082
> (not
> thoroughly tested).
This looks good to me - especially how you reduced the nesting of if's
by special-casing the "Powers of two are not biased" return. With this
change, you can as well drop the "Special case where no modulus is
required", as it'd happen to be handled the same by your new return.
OTOH, that optimization might require an extra comment on its own.
Here's what this might look like (totally untested):
https://gist.github.com/solardiz/5e3d313bbee2c1ce6e200e433b750bef
Alexander