float function
Generates a random floating point value uniformly distributed in the range from min
, inclusive, to max
,
exclusive.
If min
is not provided, it defaults to -size
, and if max
is not provided, it defaults to size
.
shrinkInterval
decides how fast the values are shrunk. If not provided, it defaults to 1
.
See also Random.nextDouble.
Implementation
Generator<double> float({double? min, double? max, double shrinkInterval = 1}) {
assert(min == null || max == null || min < max, 'min must be less than max');
return generator(
generate: (random, size) {
final actualMin = min ?? -size;
final actualMax = max ?? size;
return actualMin + random.nextDouble() * (actualMax - actualMin).abs();
},
// TODO: Try smallest input first
shrink: (input) sync* {
if (input > .0) {
final next = input - shrinkInterval;
if (next >= (min ?? 0)) {
yield next;
}
}
if (input < .0) {
final next = input + shrinkInterval;
if (next < (max ?? 0)) {
yield next;
}
}
},
);
}