You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Contrary to what I said in #760, it is safely possible to generate random floats between 0 and 1 (not including 1) in userland for 64 bit systems, by using the following construction:
random_int(0, (1 << 53) - 1) / (1 << 53)
(which is equivalent to PHP 8.3's Randomizer::nextFloat() or Randomizer::getFloat(0, 1))
This can be leveraged to generate a boolean with a specific non-integer chance as follows:
Summary
Contrary to what I said in #760, it is safely possible to generate random floats between 0 and 1 (not including 1) in userland for 64 bit systems, by using the following construction:
random_int(0, (1 << 53) - 1) / (1 << 53)
(which is equivalent to PHP 8.3's Randomizer::nextFloat() or Randomizer::getFloat(0, 1))
This can be leveraged to generate a boolean with a specific non-integer chance as follows:
See also the example in the corresponding PHP RFC: https://wiki.php.net/rfc/randomizer_additions#nextfloat
The text was updated successfully, but these errors were encountered: