2022年2月15日(火) 22:09 Tim Düsterhus <t...@bastelstu.be>:

> Hi
>
> On 2/15/22 12:48, Go Kudo wrote:
> > At first, I updated the RFC to the latest status.
> >
> > https://wiki.php.net/rfc/rng_extension
>
> Thank you, the examples are useful.
>
> > I need some time to think about the current issue. I understand its
> > usefulness, but I feel uncomfortable with the fact that the
> NumberGenerator
> > generates a string.
>
> Would you feel more comfortable if the interface would be called
> \Random\Engine or \Random\Generator (i.e. leaving out the "Number" from
> the interface name)?
>
> Engine is the term used by C++:
> https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
> Generator is the term used by Java:
>
> https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html
>
> ----------
>
> With the 'FixedForUnitTest' example you mentioned in the RFC: While for
> that specific implementation it appears pretty obvious that increasing
> numbers are generated, in practice:
>
> 1. This will result in inconsistent behavior based on the architecture.
> I can't test it due to the lack of the necessary architectures, but I
> believe the following to be accurate:
>
>      $g = new FixedForUnitTest();
>
>      $r = new Randomizer($g);
>
>      // 0100000000000000 in 64 Bit little endian
>      // 0100000002000000 in 32 Bit little endian
>      // 0000000000000001 in 64 Bit big endian
>      var_dump(bin2hex($r->getBytes(8)));
>
> 2. This analogy completely breaks down for the 'shuffle' functions which
> call the generator internally an unspecified number of times:
>
>      $g = new FixedForUnitTest();
>
>      $r = new Randomizer($g);
>
>      var_dump($r->shuffleString("abcdefghijklmnopqrstuvwxyz")); //
> wosqyrupatvxznmlkjihgfedcb
>      var_dump($r->shuffleString("abcdefghijklmnopqrstuvwxyz")); //
> fwrtjndlsyvpzuhxbqomkigeca
>
> The resulting strings look somewhat ordered, but there is no clear
> pattern, despite the underlying generator being completely predictable!
>
> > I also wonder about the point of changing RNG to XorShift128Plus. There
> are
> > a number of derived implementations, which RNG do you think is more
> > suitable?
> >
>
> I'm not an expert in RNGs, but based off this page:
> https://prng.di.unimi.it/ and the linked papers it appears that
> xoshiro256** is the overall best choice if memory usage is not a concern.
>
> Best regards
> Tim Düsterhus
>

Hi Tim.

Thanks for the good idea. I changed the NumberGenerator to Engine and
changed generate() to return a string as suggested.

The main changes since last time are as follows:

- The userland implementation can now specify the width of the random
number sequence that can be generated
- Random\Engine::nextByteSize() has been added
- Random\Engine::generate() now returns a string
- Random\Randomizer::getInt() now accepts an empty argument (like mt_rand())

At the same time, I have updated the RFC.

https://wiki.php.net/rfc/rng_extension

I have not yet come to a final conclusion on whether XorShift128Plus should
be switched to another RNG. For example, what about implementing
XorShift128Plus, but adding Xoshiro256** as well?

Reply via email to