| Conditions | 1 |
| Paths | 1 |
| Total Lines | 12 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 29 | public function generate(\GMP $max): \GMP |
||
| 30 | { |
||
| 31 | $numBits = NumberSize::bnNumBits($this->adapter, $max); |
||
| 32 | $numBytes = (int) ceil($numBits / 8); |
||
| 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 | } |
||
| 43 |