randomInt static method

int randomInt(
  1. int min,
  2. int max, [
  3. Random? random
])

Generates a random integer uniformly distributed in the range from min, inclusive, to max, exclusive.

The value of max must be larger than or equal to min. If it is equal to min, this function always returns min.

An instance of _math.Random can optionally be passed to customize the random sample distribution.

Implementation

static int randomInt(int min, int max, [_math.Random? random]) {
  random = random ?? _math.Random();
  if (min == max) {
    return min;
  }
  final _rng = _math.Random();
  return min + _rng.nextInt(max - min);
}