randomAsync method

Future<T> randomAsync({
  1. required FutureOr<T> onNotFound(),
})

Implementation

Future<T> randomAsync({
  required FutureOr<T> Function() onNotFound,
}) async {
  try {
    return this[Random().nextInt(length)];
  } catch (e) {
    return await onNotFound();
  }
}