On Wed, Dec 16, 2020 at 4:56 PM Sara Golemon <poll...@php.net> wrote:

> On Wed, Dec 16, 2020 at 8:46 AM zeriyoshi <zeriyo...@gmail.com> wrote:
> > Nice to meet you, internals.
> >
>
> Welcome! I'm about to knock down your suggestion a little, but please take
> it as constructive feedback.
>
> > First , PHP has the historical Mersenne Twister PRNG. However, this
> > implementation keeps its state in a global and cannot be handled as an
> > object like other languages (e.g. Java).
> >
>
> Can you clarify what object handling provides?  Is the intent to have an
> expanded API for producing a reliably predictable series of numbers based
> on more finely tunable seeds? Iterable PRNG generator?
>

I expect the main use-case is generation of predictable random numbers
based on a seed, in a way that does not rely on global state. mt_srand() +
mt_rand() provide the basic functionality, but because they are using
global state, any other library that also happens to use mt_rand()
somewhere will screw up your seed sequence.

You need to implement your own PRNG in userland, which will be slower (esp.
as RNGs usually require wrapping math, which is not efficiently supported
in PHP). Additionally, if you want to perform something like an
array_rand() based on your independent RNG stream, there's no way you can
do that efficiently (as you don't have random access into the underlying
data array).

As such, I do like the idea of providing this functionality, as it falls
squarely in the area of "performance sensitive and hard to implement in
userland", which is exactly the kind of functionality we can justify having
in the standard library. (The abstract functionality, no comment on the
particular implementation used here.)

Regards,
Nikita




> > So, I created a PHP Extension and proposed it to PECL.
> >
> > https://marc.info/?l=pecl-dev&m=160795415604102&w=2
> > https://github.com/zeriyoshi/php-ext-orng
> >
>
> Bundling extensions usually comes when an extension has shown widespread
> popularity/use.  With all due respect, this repo is less than two weeks old
> and has 8 stars. Who needs this and why is it not services by the PRNG and
> CSPRNG options already available?
>
> > With the development of container technology, this problem seems to be
> > getting more serious. So I think we should use the random numbers
> provided
> > by the OS (getrandom on Linux) if available.
> >
>
> We've had that since 7.0:
>
> https://www.php.net/random_bytes
> https://www.php.net/random_int
>
> -Sara
>

Reply via email to