inclusive 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, inclusive(2)
returns a 0
, 1
, or 2
, and
inclusive(2, 4)
returns 2
, 3
, or 4
.
Implementation
int inclusive(int minOrMax, [int? max]) {
if (max == null) {
max = minOrMax;
minOrMax = 0;
}
max++;
return _random.nextInt(max - minOrMax) + minOrMax;
}