doubles method
Returns a Stream of length
that produces random doubles in the range, [min] <= value < [max]
.
If length
is not given, returns an infinite Stream instead.
Contract
Throws RangeError if:
length
is not positivemin
is infinitemax
is infinitemin
>=max
- the resultant range is infinite
Example
Random.doubles(length: 5, min: 0.0, max: 1.1); // 5 values, 0.0 <= value < 1.1
Random.doubles(length: 1, min: 3.0, max: 2.0); // throws RangeError
Implementation details
This function scales the result of nextDouble. If the given range is sufficiently larger than [0.0 - 1.0)
,
certain doubles in the given range will never be returned, Pigeonhole Principle.
Implementation
@Possible({RangeError})
@useResult Stream<double> doubles({int? length, double min = 0.0, double max = 1.0}) {
if (length != null) {
RangeError.checkNotNegative(length, 'length');
}
_check(min, max);
return _generate(length, () => nextDouble() * (max - min) + min);
}