nextFromList<T> method
Generates an integer randomly picked from a list of integers. The list must not be empty.
Implementation
T nextFromList<T>(List<T> list) {
try {
return list[nextInt(list.length)];
} catch (e) {
if (list.isEmpty) {
throw ErrorOf<Random>(
message: 'Could not generate next value using the '
'extension method `nextFromList`.',
invalidState: 'The provided list is empty.',
expectedState: 'A non-empty list containing possible values.');
}
rethrow;
}
}