randomMany<T> static method

List<T> randomMany<T>(
  1. List<T> list,
  2. int count
)

Returns up to count random elements of list without replacement.

Implementation

static List<T> randomMany<T>(List<T> list, int count) {
  if (count <= 0 || list.isEmpty) return <T>[];
  final n = count > list.length ? list.length : count;
  return shuffle(list).take(n).toList();
}