#1694·Faker

Biased numbers allowing favoring of lower numbers

Author: bobanumCreated May 4, 2019Updated Oct 3, 2020
Labelsenhancement

Current biased number provider only allow 'sqrt' function, i wrote an other function. But since it implies changing the method's signature, I leave it to you.

/** * Returns a biased integer between $min and $max (both inclusive). * The distribution depends on $bias. * * if $bias > 1, results tend toward $max * if $bias ∈ [0, 1], results tend toward $min * if $bias = 1 or $bias < 0, results are linear * * @param integer $min Minimum value of the generated integers. * @param integer $max Maximum value of the generated integers. * @param number $bias A number greater than 0 * @return integer An integer between $min and $max. */ public function biasedNumberBetween($min = 0, $max = 100, $bias = 1.5) { // A 1.5 value for $bias gives exactly the same outcome as old 'sqrt' function $rand = ($bias <= 0) ? 1 : pow(mt_rand() / mt_getrandmax(), 1 / $bias); return floor($rand * ($max - $min + 1) + $min); }