atRandom method
Returns a random element from this Iterable.
For example
[1, 2, 3, 4, 5, 6].atRandom()
returns a random dice roll each time you call it.
Implementation
E atRandom({Random? random, E Function()? orElse}) {
if (isNotEmpty) {
final index = (random ?? _defaultRandom).nextInt(length);
return elementAt(index);
}
if (orElse == null) {
throw StateError('Unable to get random element from empty collection.');
}
return orElse();
}