Conditions | 3 |
Paths | 2 |
Total Lines | 12 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 3.0261 |
Changes | 0 |
1 | <?php |
||
16 | 4 | public function biasedNumberBetween(int $min = 0, int $max = 100, callable|string $function = 'sqrt'): int |
|
17 | { |
||
18 | 4 | if (!is_callable($function)) { |
|
19 | throw new ExtensionArgumentException('Given $function must be a callable'); |
||
20 | } |
||
21 | |||
22 | do { |
||
23 | 4 | $x = $this->randomizer->getInt(0, PHP_INT_MAX) / PHP_INT_MAX; |
|
24 | 4 | $y = $this->randomizer->getInt(0, PHP_INT_MAX) / (PHP_INT_MAX + 1); |
|
25 | 4 | } while ($function($x) < $y); |
|
26 | |||
27 | 4 | return (int) floor($x * ($max - $min + 1) + $min); |
|
28 | } |
||
45 |