Re: [RFC] Object-scope RNG implementation

From: Date: Mon, 18 Jan 2021 16:28:37 +0000
Subject: Re: [RFC] Object-scope RNG implementation
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-112922@lists.php.net to get a copy of this message
RFC and implementation updated.

https://wiki.php.net/rfc/object_scope_prng
https://github.com/php/php-src/pull/6568

> MT19937 returns a signed 32bit number as a result of the next() method;
the mt_rand() function returns a bit-shifted unsigned 31bit number, so the
results are not identical.

The rng_range() function has been renamed to rng_rand() and returns an
unsigned 31-bit integer like the mt_rand() function if only the $rng
argument is received.

```php
mt_srand(1234);
mt_rand() === rng_rand(new \RNG\MT19937(1234)); // true
```

This allows to completely replace the mt_rand() function with the
RNG\MT19937.

I said I wanted to initiate a vote, but there seems to be too much
discussion missing for that.
I'd like to wait and see for a while.

Regards,
Go Kudo

2021年1月17日(日) 20:02 Go Kudo <zeriyoshi@gmail.com>:

> Updated the RFC and fixed the implementation.
> Also made some additions to the RFC about when this feature might be
> useful.
>
> RFC: https://wiki.php.net/rfc/object_scope_prng
> Implementation PR: https://github.com/php/php-src/pull/6568 (All CI
> passed)
>
> The main points are as follows:
>
> - The implementation now meets all requirements. (maybe)
> - Implemented MT19937, which is compatible with PHP standard MT. The
> consistency of these is ensured by tests.
> - The implementation is now what we used to call TypeII.
> - All RNG implementations can now be inherited like regular classes. Use
> faster calls only if the class is an internal class.
> - The implementation has been heavily modified and the quality of the code
> has been improved.
>
> Currently, there are a few concerns:
>
> - MT19937 returns a signed 32bit number as a result of the next()
> method; the mt_rand() function returns a bit-shifted unsigned 31bit number,
> so the results are not identical.
>     - You can get the equivalent result with `$rng->next() << 1 &
> PHP_INT_MAX, but maybe you should have a nextUnsigned31()` method.
>     - Currently, the test uses $rng->next() << 1 & PHP_INT_MAX.
> - The implementation of MT19937 is redundant. This can be merged.
>
> Anyway, I think the code is finally ready for review.
> Once that is done, we will start voting on RFCs.
>
> Regards,
> Go Kudo
>
> 2021年1月9日(土) 19:00 Go Kudo <zeriyoshi@gmail.com>:
>
>> Hi internals.
>>
>> I think I'm ready to discuss this RFC.
>> https://wiki.php.net/rfc/object_scope_prng
>>
>> Previous internals thread: https://externals.io/message/112525
>>
>> Now is the time to let me know what you think.
>>
>> Regards,
>> Go Kudo
>>
>


Thread (14 messages)

« previous php.internals (#112922) next »