sample method

List<T> sample(
  1. int n, {
  2. int? seed,
})

Returns n random elements without replacement.

Implementation

List<T> sample(int n, {int? seed}) {
  if (n >= length) return [...this]..shuffle(math.Random(seed));
  final copy = [...this]..shuffle(math.Random(seed));
  return copy.take(n).toList();
}