Total Complexity | 6 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Coverage | 92.31% |
Changes | 0 |
1 | <?php |
||
12 | class Biased implements BiasedExtensionInterface, RandomizerAwareExtensionInterface |
||
13 | { |
||
14 | use RandomizerAwareExtensionTrait; |
||
15 | |||
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 | } |
||
29 | |||
30 | 1 | public function unbiased(): int |
|
31 | { |
||
32 | 1 | return 1; |
|
33 | } |
||
34 | |||
35 | 1 | public function linearLow(float $x): float |
|
36 | { |
||
37 | 1 | return 1 - $x; |
|
38 | } |
||
39 | |||
40 | 1 | public function linearHigh(float $x): float |
|
43 | } |
||
44 | } |
||
45 |