Random

bernoulli (p: number): 0|1

Generates a Bernoulli random variable.

Name Type Default Description
p number 0.5  

binomial (n: number, p: number): number

Generates a Binomial random variable.

Name Type Default Description
n number 1  
p number 0.5  

cauchy (): number

Generates an Cauchy random variable.

chiCDF (chi: number, deg: number): number

The chi CDF function.

Name Type Default Description
chi number    
deg number    

exponential (l: number): number

Generates an exponential random variable.

Name Type Default Description
l number 1  

find (items: Array<T>): T

Randomly selects an element from an array.

Name Type Default Description
items Array<T>    

geometric (p: number): undefined|number

Generates a geometric random variable.

Name Type Default Description
p number 0.5  

integer (a: number, b: number): number

Generates a random integer between 0 and a, or between a and b.

Name Type Default Description
a number    
b number    

integrate (fn: (x: number): number, xMin: number, xMax: number, dx: number): number

Riemann-integrates fn(x) from xMin to xMax with an interval size dx.

Name Type Default Description
fn (x: number): number    
xMin number    
xMax number    
dx number 1  

normal (m: number, v: number): number

Generates a normal random variable with mean m and variance v.

Name Type Default Description
m number 0  
v number 1  

normalPDF (x: number, m: number, v: number): number

Generates pdf(x) for the normal distribution with mean m and variance v.

Name Type Default Description
x number    
m number 1  
v number 0  

poisson (l: number): number

Generates a Poisson random variable.

Name Type Default Description
l number 1  

shuffle (a: Array<T>): Array<T>

Randomly shuffles the elements in an array a.

Name Type Default Description
a Array<T>    

smart (n: number, id: string): number

Returns a random number between 0 and n, but avoids returning the same number multiple times in a row.

Name Type Default Description
n number    
id string    

uniform (a: number, b: number): number

Generates a uniform random variable.

Name Type Default Description
a number 0  
b number 1  

weighted (weights: Array<number>): number

Chooses a random index value from weights [2, 5, 3]

Name Type Default Description
weights Array<number>    

Copyright © 2024 Mathigon.org