nextFromRange method

int nextFromRange(
  1. int minValue,
  2. int maxValue
)

Return the next random integer inclusive to minValue exclusive to maxValue.

Implementation

int nextFromRange(int minValue, int maxValue) {
  if (minValue > maxValue) {
    throw ArgumentError("Min value is greater than max value.");
  }

  int diff = maxValue - minValue;
  if (diff.abs() <= 1) {
    return minValue;
  }

  int retVal = ((sample() * diff) + minValue).toInt();
  return retVal;
}