iter-fns - v0.13.0
    Preparing search index...

    Function sample

    • Randomly samples n items the iterable uniformly, returning them in uniformly random order.

      If you need to select a single item randomly from the iterable, pass n = 1.

      If you need to sample items with varying weight, use sampleWeighted.

      This uses a reservoir sampling algorithm.

      Type Parameters

      • T

        type of the item

      Parameters

      • iterable: Iterable<T>

        the iterable

      • n: number

        the number of items to sample

      • rand: Random = random

        random number generator

      Returns T[]