randomSelection method

List<T> randomSelection({
  1. int? length,
  2. double? lengthRatio,
  3. int? minimumSize,
  4. Random? random,
  5. int? seed,
})

Implementation

List<T> randomSelection(
    {int? length,
    double? lengthRatio,
    int? minimumSize,
    math.Random? random,
    int? seed}) {
  random = math.Random(seed);

  if (length == null) {
    if (lengthRatio != null) {
      length = this.lengthRatio(lengthRatio);
    } else {
      length = random.nextInt(this.length);
    }
  }

  if (minimumSize != null && minimumSize >= 0 && length < minimumSize) {
    length = minimumSize;
  }

  if (length > this.length) {
    length = this.length;
  }

  if (length == 0) return <T>[];

  var list = shuffleCopy();
  list = list.sublist(0, length);
  return list;
}