Bernoulli

Overview


A Bernoulli random variable is a random variable that can one of two values, where the probabilities are, where the variable takes on the first value with probability p, and the second value with probability 1-p.

Generating Bernoullis


To generate a bernoulli variable, you just need to use the following simple algorithm:

  • Generate {% U \sim U(0,1) %} (uniform random)
  • if {% U \leq p %} , return 1, else return 0


Bernoulli Library


The Bernoulli Distribution Library contains a method for generating random Bernoullis.


let bl = await import('/lib/statistics/distributions/bernoulli/v1.0.0/bernoulli.mjs');
let rand = bl.random(0.2);

let rand2 = bl.random(0.2, random)
					

Contents