sample<T> method

List<T> sample<T>(
  1. List<T> items,
  2. int n
)

Samples n items from a list without replacement.

Implementation

List<T> sample<T>(List<T> items, int n) {
  assert(n <= items.length);

  final shuffled = List<T>.from(items);
  shuffle(shuffled);
  return shuffled.take(n).toList();
}