Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "iter/choices"

Index

Functions

Functions

Const choices

  • choices<T>(choices: ArrayLike<T> & Iterable<T>, weights?: ArrayLike<number>, rnd?: IRandom): IterableIterator<T>
  • Returns an infinite iterator of random choices and their (optional) weights. If weights is given, it must have at least the same size as choices. If omitted, each choice will have same probability.

    -

    example
    transduce(take(1000), frequencies(), choices("abcd", [1, 0.5, 0.25, 0.125]))
    // Map { 'c' => 132, 'a' => 545, 'b' => 251, 'd' => 72 }

    {@link @thi.ng/random#weightedRandom}

    Type parameters

    • T

    Parameters

    • choices: ArrayLike<T> & Iterable<T>
    • Optional weights: ArrayLike<number>

      -

    • Default value rnd: IRandom = SYSTEM

    Returns IterableIterator<T>

Generated using TypeDoc