(bound?: number)
| 83 | |
| 84 | // generate exclusive random number within bound |
| 85 | nextInt(bound?: number) { |
| 86 | if (bound === undefined) { |
| 87 | return next_signed(32); |
| 88 | } |
| 89 | |
| 90 | checkIsPositiveInt(bound, 0x7fffffff); |
| 91 | |
| 92 | // special case if bound is a power of two |
| 93 | if ((bound & -bound) === bound) { |
| 94 | const r = next(31) / p2_31; |
| 95 | return ~~(bound * r); |
| 96 | } |
| 97 | |
| 98 | let bits, val; |
| 99 | do { |
| 100 | bits = next(31); |
| 101 | val = bits % bound; |
| 102 | } while (bits - val + (bound - 1) < 0); |
| 103 | return val; |
| 104 | } |
| 105 | |
| 106 | nextLong() { |
| 107 | const msb = BigInt(next_signed(32)); |
nothing calls this directly
no test coverage detected