Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The output of Base::randomFloat() is biased for certain inputs #760

Open
TimWolla opened this issue Sep 15, 2023 · 0 comments
Open

The output of Base::randomFloat() is biased for certain inputs #760

TimWolla opened this issue Sep 15, 2023 · 0 comments
Labels
Projects

Comments

@TimWolla
Copy link

Summary

As per the Drawing Random Floating-Point Numbers from an Interval. Frédéric Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022. https://doi.org/10.1145/3503512 paper, the $min + rand() / randmax() * ($max - $min) construction of Base::randomFloat()

https://github.com/FakerPHP/Faker/blob/2.0/src/Faker/Provider/Base.php#L111-L132

is unsafe and depending on the inputs might:

  1. Return values outside of the requested range.
  2. Return values that are biased towards specific subintervals.

This is unfixable in userland. The only solution is to leverage PHP 8.3's Randomizer::getFloat() which will do the right thing. See the https://wiki.php.net/rfc/randomizer_additions RFC for additional details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Version 2.0
  
To do
Development

No branches or pull requests

2 participants