Conditions | 3 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
24 | 1 | private function generateRandomValueStandardNormalDistribution(int $min, int $max): int |
|
25 | { |
||
26 | 1 | $mean = (int)(($min + $max) / 2); // MW |
|
27 | 1 | $stdDeviation = (int) ($mean / 2.5); // FWHM |
|
28 | |||
29 | do { |
||
30 | 1 | $value = random_int($min, $max); |
|
31 | 1 | $probability = exp(-0.5 * (($value - $mean) / $stdDeviation) ** 2); // normal distribution |
|
32 | 1 | $randomProbability = random_int(0, mt_getrandmax()) / mt_getrandmax(); |
|
33 | |||
34 | 1 | if ($randomProbability <= $probability) { |
|
35 | 1 | return $value; |
|
36 | } |
||
37 | 1 | } while (true); |
|
38 | } |
||
40 |