randomBetween function

int randomBetween (
  1. int from,
  2. int to
)

Generates a random integer where from <= to.

Implementation

int randomBetween(int from, int to) {
  if (from > to) throw new Exception('$from cannot be > $to');
  var rand = new Random();
  return ((to - from) * rand.nextDouble()).toInt() + from;
}