FakerPHP / Faker

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

Enhancement: Use `Helper` to select random number between minimum and maximum #757

Closed localheinz closed 1 year ago

localheinz commented 1 year ago

What is the reason for this PR?

Follows #754.

💁‍♂️ Running

git grep mt_rand\(

on current 2.0 yields

.github/CONTRIBUTING.md:21:* Never use `rand()` in your provider. Faker utilizes the Mersenne Twister Randomizer, so use `mt_rand()` or any of the base generators (`randomNumber`, `randomElement`, etc.) instead.
src/Faker/ChanceGenerator.php:54:        if (mt_rand(1, 100) <= (100 * $this->weight)) {
src/Faker/Core/Number.php:19:        return mt_rand($int1, $int2);
src/Faker/Extension/Helper.php:26:        return mt_rand();
src/Faker/Extension/Helper.php:61:                $numbers .= str_pad((string) mt_rand(0, 10 ** $size - 1), $size, '0', STR_PAD_LEFT);
src/Faker/Extension/Helper.php:71:            return mt_rand(1, 9);
src/Faker/Extension/Helper.php:83:            return chr(mt_rand(97, 122));
src/Faker/Extension/Helper.php:96:            return mt_rand(0, 1) === 1 ? '#' : '?';
src/Faker/Provider/Base.php:35:        return mt_rand(0, 9);
src/Faker/Provider/Base.php:45:        return mt_rand(1, 9);
src/Faker/Provider/Base.php:94:            return mt_rand(10 ** ($nbDigits - 1), $max);
src/Faker/Provider/Base.php:97:        return mt_rand(0, $max);
src/Faker/Provider/Base.php:149:        return mt_rand($min, $max);
src/Faker/Provider/Base.php:167:        return chr(mt_rand(97, 122));
src/Faker/Provider/Base.php:177:        return chr(mt_rand(33, 126));
src/Faker/Provider/Base.php:226:            $count = mt_rand(1, $numberOfElements);
src/Faker/Provider/Base.php:237:            $index = mt_rand(0, $maxIndex);
src/Faker/Provider/Base.php:308:        return $keys[mt_rand(0, count($keys) - 1)];
src/Faker/Provider/Base.php:365:                $j = mt_rand(0, $i);
src/Faker/Provider/Base.php:495:            return mt_rand(0, 1) === 1 ? '#' : '?';
src/Faker/Provider/Base.php:651:        if (is_int($weight) && mt_rand(1, 100) <= $weight) {
src/Faker/Provider/ar_EG/Person.php:89:        $randomBirthDateTimestamp = mt_rand(strtotime('1950-Jan-10'), strtotime('2005-Dec-25'));
src/Faker/Provider/ar_EG/Person.php:94:        $birthRegistrationSequence = mt_rand(1, 500);
src/Faker/Provider/ar_EG/Person.php:103:        $randomCheckDigit = mt_rand(1, 9);
test/Faker/GeneratorTest.php:190:        $mtRandWithSeedZero = mt_rand();
test/Faker/GeneratorTest.php:192:        self::assertEquals($mtRandWithSeedZero, mt_rand(), 'seed(0) should be deterministic.');
test/Faker/GeneratorTest.php:195:        $mtRandWithoutSeed = mt_rand();
test/Faker/GeneratorTest.php:198:        self::assertNotEquals($mtRandWithoutSeed, mt_rand(), 'seed() should not be deterministic.');

Author's checklist

Summary of changes

Review checklist

localheinz commented 1 year ago

Thank you, @pimjansen!