doubleInRange method

Generator<double> doubleInRange(
  1. double? min,
  2. double? max
)

A generator that returns doubles between min, inclusive, and max, exclusive.

Implementation

Generator<core.double> doubleInRange(core.double? min, core.double? max) {
  return simple(
    generate: (random, size) {
      final actualMin = min ?? -size.toDouble();
      final actualMax = max ?? size.toDouble();
      return random.nextDouble() * (actualMax - actualMin) + actualMin;
    },
    shrink: (input) sync* {
      // Turn 200 -> 199 -> 198 ...
      if (input > 1 && input - 1 > (min ?? 0)) yield input - 1;
      if (input < -1 && input + 1 < (max ?? 0)) yield input + 1;
      // Round to some digets.
      for (var i = 10; i < 100000; i *= 10) {
        final rounded = (input * i).round() / i;
        if (rounded != input) yield rounded;
      }
    },
  );
}