Hi internals.

I implemented Type II, which was pointed out by Nikita and fixed.

https://github.com/zeriyoshi/php-src/commit/5ff8882a8fbfaf4ffd5cc42fb5853c4a1a00c182

This is much smarter and simpler than Type I, but the implementation is
more complex (partly due to my lack of knowledge).

It contains the complete implementation except for MT19937, and the
userland implementation and the native implementation are completely
separated internally. In other words, cannot inherit from native classes.

Also, I found during the implementation that the array_rand() function can
get stuck if you implement an RNG that always returns a fixed result, for
example.

```
class FixedNumberGenerator implements \RNG\RNGInterface
{
    public function next(): int
    {
        return 1;
    }

    public function next64(): int
    {
        return 2;
    }
}

$rng = new FixedNumberGenerator();
$array = range(1, 100);
array_rand($array, 2, $rng); // Oops, stucked.
```

This can be somewhat dangerous and should be kept in mind when implementing
it.

There has been no positive or negative feedback on this suggestion, and
frankly I am worried that I am continuing to act in an unpleasant manner.

Regards,
Go Kudo


2021年1月9日(土) 19:00 Go Kudo <zeriyo...@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
>

Reply via email to