Re: random_compat
| From: | Scott Arciszewski | Date: | Wed, 08 Jul 2015 10:06:58 +0000 |
| Subject: | Re: random_compat | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87071@lists.php.net to get a copy of this message | ||
You're right, I misread that part of the documentation.
Scott Arciszewski
Chief Development Officer
Paragon Initiative Enterprises
On Wed, Jul 8, 2015 at 6:03 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Wed, Jul 8, 2015 at 11:59 AM, Scott Arciszewski <scott@paragonie.com>
> wrote:
>>
>> Hi everyone,
>>
>> I'm working on a library to backport random_bytes() and random_int()
>> into PHP 5. The effort is located on Github if anyone is interested:
>> https://github.com/paragonie/random_compat
>>
>> My reason for this email is that I'm running into one compatibility
>> issue that I don't think I can safely work around: If we let
>> random_int() default to -PHP_INT_MAX and PHP_INT_MAX, then the
>> difference between the two (used to calculate the range) will overflow
>> into a float, which will lead to a loss of precision.
>>
>> My current compromise is to use -(PHP_INT_MAX/2) and PHP_INT_MAX/2,
>> but I'm not sure if there's a better solution.
>
>
> random_int() arguments don't have default values, you have to explicitly
> pass both. (Of course you still have a problem if someone does pass them :)
>
> Nikita