nextInt method
Unbiased integer in [0, n) for 1 <= n <= 2^32 (rejection sampling:
redraw while the raw value is ≥ 2^32 − (2^32 mod n)).
Implementation
int nextInt(int n) {
if (n < 1 || n > _two32) {
throw RangeError.range(n, 1, _two32, 'n');
}
final limit = _two32 - (_two32 % n);
while (true) {
final x = nextU32();
if (x < limit) return x % n;
}
}