Hi
On 2/14/22 16:44, Tim Düsterhus wrote:
Unfortunately your PR doesn't compile for me, so I can't test:
make: *** No rule to make target 'php-src/ext/standard/lcg.c', needed by
'ext/standard/lcg.lo'. Stop.
I've managed to compile it by cleaning the whole directory and rerunning
of the build steps. Not sure what I missed the first time.
I've now been able to play around with it and have some additional
discussion points:
1) Consider the following script:
<?php
use Random\NumberGenerator\XorShift128Plus;
use Random\Randomizer;
$g1 = new XorShift128Plus(2);
$g2 = clone $g1;
$r1 = new Randomizer($g1);
$r2 = new Randomizer($g2);
var_dump(\bin2hex($r1->getBytes(8)));
var_dump(\bin2hex($r2->getBytes(4)) . \bin2hex($r2->getBytes(4)));
As a user: Would you expect those two 'var_dump' calls to result in the
same output?
Personally I would. For me that implies:
1. generate() should return raw bytes instead of a number (as I
suggested before).
2. The 'Randomizer' object should buffer unused bytes internally and
only call generate() if the internal buffer is drained.
2) Why xorshift instead of xoshiro / xoroshiro?
https://vigna.di.unimi.it/xorshift/ says that:
Information about my previous xorshift-based generators can be found here, but
they have been entirely superseded by the new ones, which are faster and better.
That would imply to me that xorshift should not be used in new developments.
3) Consider the following script:
<?php
use Random\NumberGenerator\XorShift128Plus;
$g1 = new XorShift128Plus(2);
var_dump($g1);
exit;
Should the user be able to see the internal state of the Generator in
the var_dump() output?
4) Both xorshift as well as xoshiro / xoroshiro's reference
implementations include a 'jump()' function that allows one to easily
retrieve generators with distinct sequences, without needing to generate
seeds manually which might or might nor introduce a bias.
Is this something that we should provide as well?
5) As a follow-up to (4): Should the 'generate()' method be called
'next()' or 'step()' instead? Perhaps it should even be '__invoke()'?
Best regards
Tim Düsterhus
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php