ixfx
    Preparing search index...

    Function randomElementWeightedSource

    • Selects a random array index, biased by the provided weightings.

      In the below example, a will be picked 20% of the time, b 50% and so on.

      const data =    [  `a`,  `b`,  `c`,  `d` ]
      const weights = [ 0.2, 0.5, 0.1, 0.2 ]

      Type Parameters

      • V

      Parameters

      • array: ArrayLike<V>
      • weightings: number[]
      • randomSource: RandomSource = Math.random

      Returns () => V