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

    Function sampleWeighted

    • Randomly samples n items the iterable by some weight function.

      If you need to sample items with uniform weight, sample is more efficient.

      This uses the Efraimidis–Spirakis algorithm.

      Type Parameters

      • T

        type of the item

      Parameters

      • iterable: Iterable<T>

        the iterable

      • n: number

        the number of items to sample

      • weight: (x: T, i: number) => number

        the projection for the weight, defaults to always 1

      • rand: Random = random

        random number generator

      Returns T[]