Playground / Binomial Distribution from Bernoulli Trials

Flip n biased coins, many times

Binomial Distribution from Bernoulli Trials

Interactive lab

Try it: Binomial Distribution from Bernoulli Trials

A binomial variable counts the successes in n independent Bernoulli(p) trials: Pascal's triangle counts the trial sequences with k successes, , and a seeded simulation of many runs lands on that PMF.

How it works

  1. One run: n independent trials, each a success with probability p; X is the number of successes.
  2. Pascal's rule C(r, k) = C(r − 1, k − 1) + C(r − 1, k) counts the success/failure paths that end with k successes.
  3. Every such path has probability , so .
  4. Mean np and variance np(1 − p), checked against Σ k·P(X = k).
  5. Repeat the n trials many times (seeded) and overlay the observed frequencies on the exact PMF.

Default run (35 steps): X ~ Binomial(n = 10, p = 0.3): X counts the successes in 10 independent Bernoulli(0.3) trials, so X can be 0, 1, …, 10. … 200 runs: simulated mean 2.98 vs np = 3, simulated variance 2.11 vs np(1 − p) = 2.1. Largest gap is at k = 5: 0.16 simulated vs 0.103 exact.

Simplified: n ≤ 20, p in steps of 0.01, up to 1,000 simulated runs from a seeded pseudo-random generator (mulberry32), so a seed always gives the same runs.

Educational simulation

Loading the simulation…