takeRandom method

Iterable<T> takeRandom(
  1. int n
)

Implementation

Iterable<T> takeRandom(int n) sync* {
  Set<int> indices = {};
  while (indices.length < n) {
    indices.add(math.Random().nextInt(length));
  }
  for (var i in indices) {
    yield this[i];
  }
}