randomBetween function

int randomBetween(
  1. int from,
  2. int to, {
  3. AbstractRandomProvider provider = const DefaultRandomProvider(),
})

Generates a random integer where from <= to inclusive where 0 <= from <= to <= 999999999999999

Implementation

int randomBetween(int from, int to,
    {AbstractRandomProvider provider = const DefaultRandomProvider()}) {
  if (from > to) {
    throw ArgumentError('$from cannot be > $to');
  }
  if (from < minSupportedInteger) {
    throw ArgumentError(
        '|$from| is larger than the maximum supported $maxSupportedInteger');
  }

  if (to > maxSupportedInteger) {
    throw ArgumentError(
        '|$to| is larger than the maximum supported $maxSupportedInteger');
  }

  var d = provider.nextDouble();
  if (d < 0 || d >= 1) {
    throw ProviderError(d);
  }
  return _mapValue(d, from, to);
}