Skip to content
Tutorials Center
My learning

Topics

Lesson 38 of 68 · Counting

Discrete Distributions: Uniform, Binomial, Poisson, Geometric, Hypergeometric

Learn random variables, the PMF, mean and variance, then the uniform, binomial, geometric, Poisson and hypergeometric distributions, checked by simulation.

A single die roll, the number of heads in ten coin flips, the number of emails arriving in a minute, and the number of tries until a login succeeds are all examples of random quantities that take countable values. A random variable is a rule that turns each outcome of an experiment into a number, and a discrete distribution tells you how likely each number is.

Counting from permutations and combinations drives every formula here, and the rules of probability basics tie them together. Each distribution below gets its formula, its mean and variance, and a Python check, first from the definition and then by simulation.

Random variables, the PMF, mean and variance

A discrete random variable X is described by its probability mass function (PMF), p(k) = P(X = k). The values must be non-negative and sum to 1. Two numbers summarize the distribution:

  • Mean (expected value): E[X] = Σ k · p(k), the long-run average.
  • Variance: Var(X) = E[(X - μ)²] = E[X²] - μ², the average squared distance from the mean. The standard deviation is its square root.

Five workhorse distributions

Uniform Every value equally likely.
Binomial Successes in n independent tries.
Geometric Tries until the first success.
1 / 2

The helper below computes the mean and variance of any PMF stored as a dictionary, and we use it for everything that follows.

Python Mean and variance from a PMF

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Bernoulli and binomial

A Bernoulli trial has two outcomes: success with probability p, failure with 1 - p. Count the successes in n independent trials and you get the binomial distribution Binomial(n, p):

TEXT
P(X = k) = C(n, k) · p^k · (1 - p)^(n - k)
E[X] = n·p        Var(X) = n·p·(1 - p)

The binomial coefficient counts which k of the n trials succeed, and each such pattern has probability p^k (1-p)^(n-k).

Geometric

Repeat independent trials until the first success. The number of trials X needed has the geometric distribution:

TEXT
P(X = k) = (1 - p)^(k - 1) · p        for k = 1, 2, 3, ...
E[X] = 1/p        Var(X) = (1 - p)/p²

It is memoryless: if you have already failed 5 times, the chance of needing 3 more tries is the same as at the start. Because k has no upper limit, the PMF has infinitely many terms, and they still sum to 1.

Poisson

The Poisson distribution counts events in a fixed window when they occur independently at an average rate λ:

TEXT
P(X = k) = e^(-λ) · λ^k / k!
E[X] = λ        Var(X) = λ

It is the limit of Binomial(n, p) when n is large, p is small and n·p = λ: think of a million drivers each with a tiny chance of an accident today.

Hypergeometric

Draw n items without replacement from N items of which K are successes. The number of successes X has

TEXT
P(X = k) = C(K, k) · C(N - K, n - k) / C(N, n)
E[X] = n·K/N

It looks like the binomial, but the draws are dependent: each removal changes the odds for the next. Quality inspection and card games are typical uses.

Python PMFs from formulas, checked against simulation

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each total is 1, the computed means and variances match the formulas, and the simulated averages land near the theory. The last lines show the binomial probability converging to the Poisson one as n grows with n · p fixed.

Which distribution fits?

Situation Distribution
One of m equally likely values Uniform
Number of successes in n independent trials, same p Binomial
Number of trials until the first success Geometric
Number of rare events in a time window Poisson
Successes when sampling without replacement from a finite pool Hypergeometric

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. You flip a fair coin 10 times. What is the mean of the number of heads?

    For Binomial(n, p) the mean is n·p = 10 × 0.5 = 5.
  2. 2. Which distribution describes the number of rolls of a die until the first 6?

    You count independent trials up to and including the first success, which is a geometric random variable with p = 1/6.
  3. 3. What is the mean of a Poisson distribution with rate 7?

    A Poisson distribution has mean and variance both equal to its rate λ.
  4. 4. Why is drawing 5 cards from a deck hypergeometric rather than binomial?

    Each removed card changes the probabilities for the next draw. The binomial needs independent trials with a constant success probability.
  5. 5. For a geometric distribution with p = 0.2, what is the expected number of trials?

    E[X] = 1/p = 1/0.2 = 5.

Summary

  • A random variable maps outcomes to numbers; its PMF gives P(X = k) and sums to 1. The mean is Σ k·p(k) and the variance is E[X²] - μ².
  • Uniform: all values equally likely. Binomial (n, p): successes in n trials, mean np, variance np(1-p).
  • Geometric p: trials until first success, mean 1/p, memoryless.
  • Poisson λ: events per window, mean and variance λ, the limit of rare-event binomials.
  • Hypergeometric: successes when sampling without replacement, with a ratio of binomial coefficients.

Next: Ramsey Theory, where counting arguments prove that order must appear in large structures.