FakerPHP / Faker

Faker is a PHP library that generates fake data for you
https://fakerphp.github.io
Other
3.63k stars 353 forks source link

Enhancement: Use `Helper` to determine largest random number #756

Closed localheinz closed 1 year ago

localheinz commented 1 year ago

What is the reason for this PR?

Follows #754.

Running

git grep mt_getrandmax\(\)

on current 2.0 yields

src/Faker/Core/Number.php:63:        return round($min + $this->numberBetween() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
src/Faker/Core/Number.php:73:        if ($max > mt_getrandmax()) {
src/Faker/Core/Number.php:74:            throw new \InvalidArgumentException('randomNumber() can only generate numbers up to mt_getrandmax()');
src/Faker/Extension/Helper.php:45:            $maxAtOnce = strlen((string) mt_getrandmax()) - 1;
src/Faker/Extension/NumberExtension.php:45:     * The maximum value returned is mt_getrandmax()
src/Faker/Generator.php:903:     * The maximum value returned is mt_getrandmax()
src/Faker/Provider/Base.php:68:     * The maximum value returned is mt_getrandmax()
src/Faker/Provider/Base.php:88:        if ($max > mt_getrandmax()) {
src/Faker/Provider/Base.php:89:            throw new \InvalidArgumentException('randomNumber() can only generate numbers up to mt_getrandmax()');
src/Faker/Provider/Base.php:130:        return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
src/Faker/Provider/Base.php:452:            $maxAtOnce = strlen((string) mt_getrandmax()) - 1;
src/Faker/Provider/Base.php:645:        if ($weight > 0 && $weight < 1 && mt_rand() / mt_getrandmax() <= $weight) {
src/Faker/Provider/Biased.php:26:            $x = mt_rand() / mt_getrandmax();
src/Faker/Provider/Biased.php:27:            $y = mt_rand() / (mt_getrandmax() + 1);
src/Faker/Provider/bg_BG/Payment.php:42:            self::randomNumber(5, true), // workaround for mt_getrandmax() limitation

Author's checklist

Summary of changes

Review checklist

localheinz commented 1 year ago

Thank you, @pimjansen!