nextDouble method
Returns the next double in the iterable.
Contract
Throws:
- a StateError if there are no more doubles in the iterable.
- a RangeError if a double in the iterable is outside the range,
0 <= double < 1.0
.
Example
final random = FakeRandom(doubles: [0.1, 0.2]);
random.nextDouble(); // 0.1
random.nextDouble(); // 0.2
random.nextDouble(); // throws StateError
Implementation
@override
@useResult double nextDouble() {
if (!_doubles.moveNext()) {
throw StateError('FakeRandom presently does not contain a double. Try supply more doubles to `FakeRandom(doubles: [...])`.');
}
if (_doubles.current < 0.0 || 1.0 <= _doubles.current) {
throw RangeError('The current double, ${_doubles.current} is outside the range, `0.0 <= ${_doubles.current} < 1.0`. Try change the doubles supplied to `FakeRandom(doubles: [...])`.');
}
return _doubles.current;
}