FakerPHP / Faker

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

Enhancement: Use `Helper` to generate random number without arguments #755

Closed localheinz closed 9 months ago

localheinz commented 9 months ago

What is the reason for this PR?

Follows #754.

πŸ’β€β™‚οΈ Following up on using the Helper to select a random element from a list of elements, this - as an intermediate step - moves generating a random number without any arguments to the Helper.

Running

git grep mt_rand\(\)

on current 2.0 yields

src/Faker/ORM/Doctrine/EntityPopulator.php:243:            $id = mt_rand();
src/Faker/Provider/Base.php:130:        return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $nbMaxDecimals);
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);
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

pimjansen commented 9 months ago

Can you do quick rebase?

localheinz commented 9 months ago

@pimjansen

Rebased!

localheinz commented 9 months ago

Thank you, @pimjansen!