Conditions | 1 |
Paths | 1 |
Total Lines | 14 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function generate(\GMP $max) |
||
29 | { |
||
30 | $numBits = NumberSize::bnNumBits($this->adapter, $max); |
||
31 | $numBytes = ceil($numBits / 8); |
||
32 | |||
33 | // Generate an integer of size >= $numBits |
||
34 | $bytes = random_bytes($numBytes); |
||
35 | $value = $this->adapter->stringToInt($bytes); |
||
36 | |||
37 | $mask = gmp_sub(gmp_pow(2, $numBits), 1); |
||
38 | $integer = gmp_and($value, $mask); |
||
39 | |||
40 | return $integer; |
||
41 | } |
||
42 | } |
||
43 |