Interface RandomBernoulli

A configurable random 0 or 1 generator according to a Bernoulli distribution.

interface RandomBernoulli {
    source(source): RandomBernoulli;
    (p): (() => number);
}

Hierarchy

  • Returns a function for generating either 1 or 0 according to a Bernoulli distribution with 1 being returned with success probability p and 0 with failure probability q = 1 - p. The value p is in the range [0, 1].

    Parameters

    • p: number

      p

    Returns (() => number)

      • (): number
      • Returns a function for generating either 1 or 0 according to a Bernoulli distribution with 1 being returned with success probability p and 0 with failure probability q = 1 - p. The value p is in the range [0, 1].

        Returns number

Methods

Methods

  • Returns the same type of function for generating random numbers but where the given random number generator source is used as the source of randomness instead of Math.random. This is useful when a seeded random number generator is preferable to Math.random.

    Parameters

    • source: (() => number)

      Source (pseudo-)random number generator implementing the Math.random interface. The given random number generator must implement the same interface as Math.random and only return values in the range [0, 1).

        • (): number
        • Returns number

    Returns RandomBernoulli