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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php