randomEleSet<T> static method

Set<T> randomEleSet<T>(
  1. Iterable<T> collection,
  2. int count
)

Implementation

static Set<T> randomEleSet<T>(Iterable<T> collection, int count) {
  final source = collection.toSet().toList();
  if (count > source.length) throw ArgumentError("Count exceeds collection size");
  final result = <T>{};
  final limit = source.length;
  while (result.length < count) {
    result.add(randomEle(source, limit));
  }
  return result;
}