Interface RngDistributionsInterface

A version of RngInterface that includes lots of extra distributions.

Depending on your integration, you may not need this.

interface RngDistributionsInterface {
    bates(options?: {
        n?: number;
    }): number;
    bates(n?: number): number;
    batesgaussian(n: number): number;
    batesgaussian(options?: {
        n?: number;
    }): number;
    bernoulli(options?: {
        p?: number;
    }): number;
    bernoulli(p?: number): number;
    beta(options?: {
        alpha?: number;
        beta?: number;
    }): number;
    betaBinomial(options?: {
        alpha?: number;
        beta?: number;
        n?: number;
    }): number;
    binomial(options?: {
        n?: number;
        p?: number;
    }): number;
    cauchy(options?: {
        median?: number;
        scale?: number;
    }): number;
    chiSquared(options?: {
        k?: number;
    }): number;
    chiSquared(k?: number): number;
    exponential(options?: {
        rate?: number;
    }): number;
    exponential(rate?: number): number;
    gamma(options?: {
        rate?: number;
        scale?: number;
        shape?: number;
    }): number;
    hermite(options?: {
        lambda1?: number;
        lambda2?: number;
    }): number;
    hypergeometric(options?: {
        k?: number;
        K?: number;
        n?: number;
        N?: number;
    }): number;
    irwinHall(options?: {
        n?: number;
    }): number;
    irwinHall(n?: number): number;
    kumaraswamy(options?: {
        alpha?: number;
        beta?: number;
    }): number;
    laplace(options?: {
        mean?: number;
        scale?: number;
    }): number;
    logistic(options?: {
        mean?: number;
        scale?: number;
    }): number;
    logNormal(options?: {
        mean?: number;
        stddev?: number;
    }): number;
    pareto(options?: {
        location?: number;
        scale?: number;
        shape?: number;
    }): number;
    poisson(options?: {
        lambda?: number;
    }): number;
    poisson(lambda?: number): number;
    rademacher(): -1 | 1;
    rayleigh(options?: {
        scale?: number;
    }): number;
    rayleigh(scale?: number): number;
    studentsT(options?: {
        nu?: number;
    }): number;
    studentsT(nu?: number): number;
    wignerSemicircle(options?: {
        R?: number;
    }): number;
    wignerSemicircle(R?: number): number;
}

Implemented by

Distributions

  • Mean of n uniformly distributed values

    Support: [0, 1]

    Parameters

    • Optionaloptions: {
          n?: number;
      }
      • Optionaln?: number

        Number of values to sum

    Returns number

    The mean of n uniform values

    rng.bates({ n: 6 });
    rng.bates(6);

    NumberValidationError If the input parameters are not valid.

  • Mean of n uniformly distributed values

    Support: [0, 1]

    Parameters

    • Optionaln: number

      Number of values to sum

    Returns number

    The mean of n uniform values

    rng.bates({ n: 6 });
    rng.bates(6);

    NumberValidationError If the input parameters are not valid.

  • A version of the bates distribution that returns gaussian normally distributed results, with n acting as a shape parameter.

    Parameters

    • n: number

      Number of values to sum

    Returns number

    The mean of n uniform values

    NumberValidationError If the input parameters are not valid.

  • A version of the bates distribution that returns gaussian normally distributed results, with n acting as a shape parameter.

    Parameters

    • Optionaloptions: {
          n?: number;
      }
      • Optionaln?: number

        Number of values to sum

    Returns number

    The mean of n uniform values

    NumberValidationError If the input parameters are not valid.

  • Probability that random number is less than p, returns 1 or 0.

    Support: {0, 1}

    Parameters

    • Optionaloptions: {
          p?: number;
      }
      • Optionalp?: number

        The probability of success, from [0 to 1], default 0.5

    Returns number

    1 or 0, depending on if random number was less than p

    rng.bernoulli({ p: 0.5 });
    rng.bernoulli(0.5);

    NumberValidationError If the input parameters are not valid.

  • Probability that random number is less than p, returns 1 or 0.

    Support: {0, 1}

    Parameters

    • Optionalp: number

      The probability of success, from [0 to 1], default 0.5

    Returns number

    1 or 0, depending on if random number was less than p

    rng.bernoulli({ p: 0.5 });
    rng.bernoulli(0.5);

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Beta distribution.

    Support: (0, 1)

    Parameters

    • Optionaloptions: {
          alpha?: number;
          beta?: number;
      }
      • Optionalalpha?: number

        The alpha parameter of the Beta distribution, must be positive, default 0.5.

      • Optionalbeta?: number

        The beta parameter of the Beta distribution, must be positive, default 0.5.

    Returns number

    A value from the Beta distribution, (0, 1).

    rng.beta({ alpha = 0.5, beta = 0.5 })
    rng.beta({ alpha = 1, beta = 2 })
    rng.beta({ beta = 1 })

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Beta-binomial distribution.

    Support: {0, 1, 2, ..., n}

    Parameters

    • Optionaloptions: {
          alpha?: number;
          beta?: number;
          n?: number;
      }
      • Optionalalpha?: number

        The alpha parameter of the Beta distribution, default 1, must be positive.

      • Optionalbeta?: number

        The beta parameter of the Beta distribution, default 1, must be positive.

      • Optionaln?: number

        The number of trials, default 1, must be positive integer.

    Returns number

    The number of successes in n trials, {0, 1, 2, ..., n}

    rng.betaBinomial({ alpha = 1, beta = 2, n = 10 })
    rng.betaBinomial({ n = 100 })

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Binomial distribution.

    Probability distribution of getting number of successes of n trials of a boolean trial with probability p

    Support: {0, 1, 2, ..., n}

    Parameters

    • Optionaloptions: {
          n?: number;
          p?: number;
      }
      • Optionaln?: number

        The number of trials, must be positive integer, default 1.

      • Optionalp?: number

        The probability of success, must be a number between 0 and 1 inclusive, default 0.5.

    Returns number

    The number of successes, {0, 1, 2, ..., n}.

    rng.binomial({ n = 1, p = 0.5 });
    rng.binomial({ n = 100, p = 0.1 });

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Cauchy distribution.

    Support: (-∞, +∞)

    @example:

    rng.cauchy({ median: 2, scale: 1 }) rng.cauchy({ median: 2 }) rng.cauchy({ scale: 1 })

    Parameters

    • Optionaloptions: {
          median?: number;
          scale?: number;
      }
      • Optionalmedian?: number

        The location parameter (median, sometimes called x0) - default 0.

      • Optionalscale?: number

        The scale parameter, must be positive - default 1.

    Returns number

    A value from the Cauchy distribution (-∞, +∞).

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Chi-squared distribution.

    Support: [0, ∞)

    @example:

    rng.chiSquared({ k: 2 }) rng.chiSquared(2) // Equivalent

    Parameters

    • Optionaloptions: {
          k?: number;
      }
      • Optionalk?: number

        The degrees of freedom, must be a postive integer - default 1.

    Returns number

    A value from the Chi-squared distribution [0, ∞).

    NumberValidationError If the input parameter is not valid.

  • Generates a value from the Chi-squared distribution.

    Support: [0, ∞)

    @example:

    rng.chiSquared({ k: 2 }) rng.chiSquared(2) // Equivalent

    Parameters

    • Optionalk: number

      The degrees of freedom, must be a postive integer - default 1..

    Returns number

    A value from the Chi-squared distribution [0, ∞).

    NumberValidationError If the input parameter is not valid.

  • This function uses the inverse transform sampling method to generate an exponentially distributed random variable.

    Support: [0, ∞)

    Parameters

    • Optionaloptions: {
          rate?: number;
      }
      • Optionalrate?: number

        The rate, must be > 0, default 1

    Returns number

    rng.exponential({ rate: 1 });
    rng.exponential(1);

    NumberValidationError If the input parameters are not valid.

  • This function uses the inverse transform sampling method to generate an exponentially distributed random variable.

    Support: [0, ∞)

    Parameters

    • Optionalrate: number

      The rate, must be > 0, default 1

    Returns number

    rng.exponential({ rate: 1 });
    rng.exponential(1);

    NumberValidationError If the input parameters are not valid.

  • Generates a random number from the Gamma distribution.

    Support: (0, ∞)

    Parameters

    • Optionaloptions: {
          rate?: number;
          scale?: number;
          shape?: number;
      }
      • Optionalrate?: number

        The rate parameter, must be postive, default 1.

      • Optionalscale?: number

        The scale parameter, must be postive, ( = 1/rate).

      • Optionalshape?: number

        The shape parameter, must be postive, default 1.

    Returns number

    A random number from the Gamma distribution, from (0, ∞).

    rng.gamma({ shape = 0.5, rate = 0.5 })
    rng.gamma({ shape = 0.5, scale = 2 })
    rng.gamma({ shape = 0.5, rate = 0.5, scale = 2 }) // Redundant as scale = 1 / rate
    rng.gamma({ shape = 0.5, rate = 2, scale = 2 }) // Error('Cannot supply scale and rate')

    If both scale and rate are given and are not reciprocals of each other

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Hermite distribution.

    Support: {0, 1, 2, 3, ...}

    @example:

    rng.hermite({ lambda1: 1, lambda2: 2 }) rng.hermite({ lambda1: 1 }) rng.hermite({ lambda2: 2 })

    Parameters

    • Optionaloptions: {
          lambda1?: number;
          lambda2?: number;
      }
      • Optionallambda1?: number

        The mean of the first Poisson process, must be positive.

      • Optionallambda2?: number

        The mean of the second Poisson process, must be positive.

    Returns number

    A value from the Hermite distribution, {0, 1, 2, 3, ...}

    NumberValidationError If the input parameters are not valid.

  • This function uses combinations to calculate probabilities for the hypergeometric distribution.

    The hypergeometric distribution is a discrete probability distribution that describes the probability of k successes (random draws for which the object drawn has a specified feature) in n draws, without replacement, from a finite population of size N that contains exactly K objects with that feature

    Support: {max(0, n+K-N), ..., min(n, K)}

    Parameters

    • Optionaloptions: {
          k?: number;
          K?: number;
          n?: number;
          N?: number;
      }
      • Optionalk?: number

        The number of observed successes, must be positive integer lteq K and n.

      • OptionalK?: number

        The number of successes in the population, must be positive integer lteq N.

      • Optionaln?: number

        The number of draws, must be positive integer lteq N.

      • OptionalN?: number

        The population size, must be positive integer.

    Returns number

    The probability of exactly k successes in n draws, {max(0, n+K-N), ..., min(n, K)}.

    rng.hypergeometric({ N: 50, K: 10, n: 5 });
    rng.hypergeometric({ N: 50, K: 10, n: 5, k: 2 });

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Kumaraswamy distribution.

    Support: (0, 1)

    @example:

    rng.kumaraswamy({ alpha: 1, beta: 2 }) rng.kumaraswamy({ alpha: 1 }) rng.kumaraswamy({ beta: 2 })

    Parameters

    • Optionaloptions: {
          alpha?: number;
          beta?: number;
      }
      • Optionalalpha?: number

        The first shape parameter of the Kumaraswamy distribution, must be positive.

      • Optionalbeta?: number

        The second shape parameter of the Kumaraswamy distribution, must be positive.

    Returns number

    A value from the Kumaraswamy distribution, (0, 1).

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Laplace distribution.

    Support: (-∞, +∞)

    @example:

    rng.laplace({ mean: 2, scale: 1 }) rng.laplace({ mean: 2 }) rng.laplace({ scale: 1 })

    Parameters

    • Optionaloptions: {
          mean?: number;
          scale?: number;
      }
      • Optionalmean?: number

        The location parameter (mean) - default 0.

      • Optionalscale?: number

        The scale parameter, must be positive - default 1.

    Returns number

    A value from the Laplace distribution (-∞, +∞).

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Logistic distribution.

    Support: (-∞, +∞)

    @example:

    rng.logistic({ mean: 2, scale: 1 }) rng.logistic({ mean: 2 }) rng.logistic({ scale: 1 })

    Parameters

    • Optionaloptions: {
          mean?: number;
          scale?: number;
      }
      • Optionalmean?: number

        The location parameter (mean) - default 0.

      • Optionalscale?: number

        The scale parameter, must be positive - default 1.

    Returns number

    A value from the Logistic distribution (-∞, +∞).

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Log-Normal distribution.

    Support: (0, ∞)

    @example:

    rng.logNormal({ mean: 2, stddev: 1 }) rng.logNormal({ mean: 2 }) rng.logNormal({ stddev: 1 })

    Parameters

    • Optionaloptions: {
          mean?: number;
          stddev?: number;
      }
      • Optionalmean?: number

        The mean of the underlying normal distribution - default 0.

      • Optionalstddev?: number

        The standard deviation of the underlying normal distribution, must be positive - default 1.

    Returns number

    A value from the Log-Normal distribution (0, ∞).

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Generalized Pareto distribution.

    Support: [scale, ∞)

    Parameters

    • Optionaloptions: {
          location?: number;
          scale?: number;
          shape?: number;
      }
      • Optionallocation?: number

        The location parameter, default 0.

      • Optionalscale?: number

        The scale parameter, must be positive ( > 0), default 1.

      • Optionalshape?: number

        The shape parameter, must be >= 0, default 0.5.

    Returns number

    A value from the Generalized Pareto distribution, [scale, ∞).

    rng.pareto({ shape: 0.5, scale: 1, location: 0 });
    rng.pareto({ location: 0 });
    rng.pareto({ scale: 1 });
    rng.pareto({ shape: 0.5 });

    NumberValidationError If the input parameters are not valid.

  • This function uses the fact that the Poisson distribution can be generated using a series of random numbers multiplied together until their product is less than e^(-lambda). The number of terms needed is the Poisson-distributed random variable.

    Support: {1, 2, 3 ...}

    Parameters

    • Optionaloptions: {
          lambda?: number;
      }
      • Optionallambda?: number

        Control parameter, must be positive, default 1.

    Returns number

    Poisson distributed random number, {1, 2, 3 ...}

    rng.poisson({ lambda: 1 });
    rng.poisson(1);

    NumberValidationError If the input parameters are not valid.

  • This function uses the fact that the Poisson distribution can be generated using a series of random numbers multiplied together until their product is less than e^(-lambda). The number of terms needed is the Poisson-distributed random variable.

    Support: {1, 2, 3 ...}

    Parameters

    • Optionallambda: number

      Control parameter, must be positive, default 1.

    Returns number

    Poisson distributed random number, {1, 2, 3 ...}

    rng.poisson({ lambda: 1 });
    rng.poisson(1);

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Rademacher distribution.

    Support: {-1, 1}

    Returns -1 | 1

    either -1 or 1 with 50% probability

    rng.rademacher();
    
  • Generates a value from the Rayleigh distribution

    Support: [0, ∞)

    @example:

    rng.rayleigh({ scale: 2 }) rng.rayleigh(2) // Equivalent

    Parameters

    • Optionaloptions: {
          scale?: number;
      }
      • Optionalscale?: number

        The scale parameter of the Rayleigh distribution, must be > 0 - default 1.

    Returns number

    A value from the Rayleigh distribution [0, ∞).

    NumberValidationError If the input parameter is not valid.

  • Generates a value from the Rayleigh distribution

    Support: [0, ∞)

    @example:

    rng.rayleigh({ scale: 2 }) rng.rayleigh(2) // Equivalent

    Parameters

    • Optionalscale: number

      The scale parameter of the Rayleigh distribution, must be > 0 - default 1.

    Returns number

    A value from the Rayleigh distribution [0, ∞).

    NumberValidationError If the input parameter is not valid.

  • Generates a value from the Student's t-distribution.

    Support: (-∞, ∞)

    @example:

    rng.studentsT({ nu: 10 }) rng.studentsT(10)

    Parameters

    • Optionaloptions: {
          nu?: number;
      }
      • Optionalnu?: number

        The degrees of freedom, default 1, must be positive.

    Returns number

    A value from the Student's t-distribution, (-∞, ∞).

    NumberValidationError If the input parameter is not valid.

  • Generates a value from the Student's t-distribution.

    Support: (-∞, ∞)

    @example:

    rng.studentsT({ nu: 10 }) rng.studentsT(10)

    Parameters

    • Optionalnu: number

      The degrees of freedom, must be positive, default 1

    Returns number

    A value from the Student's t-distribution, (-∞, ∞).

    NumberValidationError If the input parameter is not valid.

  • Generates a value from the Wigner semicircle distribution.

    Support: [-R; +R]

    @example:

    rng.wignerSemicircle({ R: 1 }) rng.wignerSemicircle(1)

    Parameters

    • Optionaloptions: {
          R?: number;
      }
      • OptionalR?: number

        The radius of the semicircle, must be positive, default 1.

    Returns number

    A value from the Wigner semicircle distribution, [-R; +R].

    NumberValidationError If the input parameters are not valid.

  • Generates a value from the Wigner semicircle distribution.

    Support: [-R; +R]

    @example:

    rng.wignerSemicircle({ R: 1 }) rng.wignerSemicircle(1)

    Parameters

    • OptionalR: number

      The radius of the semicircle, must be positive, default 1.

    Returns number

    A value from the Wigner semicircle distribution, [-R; +R].

    NumberValidationError If the input parameters are not valid.