range method
Gets a random int within a given range. If max
is given, then it is
in the range [minOrMax, max)
. Otherwise, it is [0, minOrMax)
. In
other words, range(3)
returns a 0
, 1
, or 2
, and range(2, 5)
returns 2
, 3
, or 4
.
Implementation
int range(int minOrMax, [int? max]) {
if (max == null) {
max = minOrMax;
minOrMax = 0;
}
return _random.nextInt(max - minOrMax) + minOrMax;
}