pickMany<T> static method

List<T> pickMany<T>(
  1. List<T> values, {
  2. int? count,
})

Returns a random subset of the given values with a random size between min and max (inclusive).

Implementation

static List<T> pickMany<T>(List<T> values, {int? count}) {
  count ??= values.length;

  if (count < 0) {
    throw ArgumentError('count must be >= 0');
  }
  if (count > values.length) {
    throw ArgumentError('count must be <= values.length');
  }

  final list = List<T>.from(values);
  list.shuffle(math.Random());
  return list.take(count).toList();
}