Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-09-08 Thread Tom Worster
On 8 Sep 2017, at 8:31, Solar Designer wrote: On Fri, Sep 08, 2017 at 07:56:23AM -0400, Tom Worster wrote: From: Nikita Popov Sorry for the long delay. I've just applied https://github.com/php/php-src/commit/fd07302024bc47082b13b32217147fd39d1e9e61 to the 7.2 branch. Davey, Joe, do we want

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-09-08 Thread Joe Watkins
Feels too late for 7.1 Cheers Joe On Fri, Sep 8, 2017 at 1:31 PM, Solar Designer wrote: > On Fri, Sep 08, 2017 at 07:56:23AM -0400, Tom Worster wrote: > > From: Nikita Popov > > > > > >Sorry for the long delay. I've just applied > > >https://github.com/php/php-src/commit/fd07302024bc47082b13b3

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-09-08 Thread Solar Designer
On Fri, Sep 08, 2017 at 07:56:23AM -0400, Tom Worster wrote: > From: Nikita Popov > > > >Sorry for the long delay. I've just applied > >https://github.com/php/php-src/commit/fd07302024bc47082b13b32217147fd39d1e9e61 > >to the 7.2 branch. > > > >Davey, Joe, do we want to take action here for 7.1? It

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-09-08 Thread Tom Worster
From: Nikita Popov Sorry for the long delay. I've just applied https://github.com/php/php-src/commit/fd07302024bc47082b13b32217147fd39d1e9e61 to the 7.2 branch. Davey, Joe, do we want to take action here for 7.1? It's a pretty severe bias, but fixing it is going to change seed sequences. I t

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-09-07 Thread Solar Designer
On Thu, Sep 07, 2017 at 08:23:22PM +0200, Nikita Popov wrote: > Sorry for the long delay. I've just applied > https://github.com/php/php-src/commit/fd07302024bc47082b13b32217147fd39d1e9e61 > to the 7.2 branch. Thank you! Maybe you'd add similar tests for 64-bit ranges? Right now, rand_range64()'

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-09-07 Thread Nikita Popov
On Wed, Aug 23, 2017 at 10:05 PM, Solar Designer wrote: > On Thu, Aug 17, 2017 at 03:18:30PM +0200, Solar Designer wrote: > > On Thu, Aug 17, 2017 at 12:57:56AM +0200, Nikita Popov wrote: > > > On Thu, Aug 17, 2017 at 12:02 AM, Solar Designer > wrote: > > > > One difference I didn't notice at fi

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-23 Thread Solar Designer
On Thu, Aug 17, 2017 at 03:18:30PM +0200, Solar Designer wrote: > On Thu, Aug 17, 2017 at 12:57:56AM +0200, Nikita Popov wrote: > > On Thu, Aug 17, 2017 at 12:02 AM, Solar Designer wrote: > > > One difference I didn't notice at first: the currently committed code > > > does only one php_mt_rand()

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-17 Thread Solar Designer
On Thu, Aug 17, 2017 at 12:57:56AM +0200, Nikita Popov wrote: > On Thu, Aug 17, 2017 at 12:02 AM, Solar Designer wrote: > > One difference I didn't notice at first: the currently committed code > > does only one php_mt_rand() call per loop iteration when it's skipping > > "numbers over the limit",

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-16 Thread Nikita Popov
On Thu, Aug 17, 2017 at 12:02 AM, Solar Designer wrote: > On Wed, Aug 16, 2017 at 11:41:55PM +0200, Solar Designer wrote: > > 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

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-16 Thread Solar Designer
On Wed, Aug 16, 2017 at 11:41:55PM +0200, Solar Designer wrote: > 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

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-16 Thread Solar Designer
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

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-16 Thread Nikita Popov
On Wed, Aug 16, 2017 at 9:47 PM, Leigh wrote: > On Wed, 16 Aug 2017 at 20:13 Solar Designer wrote: > > > Also, why even bother to support ranges beyond 32-bit? Sounds like a > > misfeature to me, considering it won't(?) be universally available on > > all PHP builds anyway (not on 32-bit ones,

Re: [PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-16 Thread Leigh
On Wed, 16 Aug 2017 at 20:13 Solar Designer wrote: > Also, why even bother to support ranges beyond 32-bit? Sounds like a > misfeature to me, considering it won't(?) be universally available on > all PHP builds anyway (not on 32-bit ones, right?) and thus shouldn't(?) > be relied upon by applica

[PHP-DEV] PHP 7.1.0 to 7.2.0beta2 mt_rand() modulo bias bug

2017-08-16 Thread Solar Designer
Hi, It is well-known that it is impossible to map e.g. a 32-bit random number with a uniform distribution over its full range of values onto a range with fewer different values while maintaining a uniform distribution, except when the target range contains a whole power of 2 number of different va