intInRange method

Generator<int> intInRange(
  1. int? min,
  2. int? max
)

A generator that returns ints between min, inclusive, to max, exclusive.

Implementation

Generator<core.int> intInRange(core.int? min, core.int? max) {
  if (min != null && max != null) assert(min < max);
  return simple(
    generate: (random, size) {
      final actualMin = min ?? (max == null ? -size : (max - size - 1));
      final actualMax = max ?? (min == null ? size : (min + size + 1)) + 1;
      return random.nextIntInRange(actualMin, actualMax);
    },
    shrink: (input) sync* {
      if (input > 0 && input > (min ?? 0)) yield input - 1;
      if (input < 0 && input < (max ?? 0)) yield input + 1;
    },
  );
}