between static method
int
between(
- int from,
- int to, {
- AbstractRandomProvider provider = const DefaultRandomProvider(),
Generates a random integer where from
<= to
inclusive
where 0 <= from <= to <= 999999999999999
Implementation
static int between(
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',
);
}
final d = provider.nextDouble();
if (d < 0 || d >= 1) {
throw ProviderError(d);
}
return _mapValue(d, from, to);
}