Re: [RFC] Random Extension 3.0
| From: | Nikita Popov | Date: | Tue, 07 Sep 2021 08:21:49 +0000 |
| Subject: | Re: [RFC] Random Extension 3.0 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115981@lists.php.net to get a copy of this message | ||
On Sat, Sep 4, 2021 at 10:57 PM Marc <marc@mabe.berlin> wrote:
>
> On 9/2/21 5:10 PM, Go Kudo wrote:
> > Hi Internals.
> >
> > Expanded from the previous RFC and changed it to an RFC that organizes
> the
> > whole PHP random number generator. Also, the target version has been
> > changed to 8.2.
> >
> > https://wiki.php.net/rfc/rng_extension
> > https://github.com/php/php-src/pull/7453
> >
> > Hopefully you will get some good responses.
>
> For me (user land developer with no voting power) your RFC looks pretty :)
>
> Beside the abstract vs interface question I have some other notes:
>
> On the one hand you define "getBytes()" which returns a string and on
> the other hand you define "shuffleString()" - is the first one a binary
> string and the other a charset dependent string? I guess here
> "shuffleString()" works on byte level and so it should be "shuffleBytes()".
>
> Why are there no default values for min/max on "getInt()" - It seems
> unnecessary to me to pass min/max arguments if you are just interested
> in a random integer or passing max as well if you are interested in a
> positive integer only.
>
Because the default range is not obvious. For example mt_rand() without
min/max will actually return only non-negative integers, so someone might
expect $random->getInt() to do the same, even though it makes very little
sense. $random->getInt($n) could be interpreted either as a number in
$n..PHP_INT_MAX (if we just see it as leaving $max at the default value),
or 0..$n-1 (a very common convention for single-argument random integer
functions). Requiring both arguments makes the meaning unambiguous.
Regards,
Nikita