nextBytes method
Generates a list of non-negative random bytes uniformly distributed in
the range from min, inclusive, to max, exclusive.
count determines how many bytes will be generated. Must be greater
than 0.
The provided range, given by min and max, must be valid. A range
from min to max is valid if 0 ≤ min < max ≤ 256.
Implementation
Uint8List nextBytes(
int count, {
int min = 0,
int max = 256,
}) {
if (count < 0) {
throw ArgumentError.value(
count,
"count",
"Must be greater than 0",
);
}
RangeError.checkValueInInterval(min, 0, 255, "min");
RangeError.checkValueInInterval(max, 1, 256, "max");
if (min >= max) {
throw RangeError(
"The minimum value ($min) must be less than the maximum value ($max)",
);
}
final bytes = Uint8List(count);
for (var i = 0; i < count; i++) {
bytes[i] = nextIntBetween(min, max);
}
return bytes;
}