All lessons

Module 3: Distributions · Lesson 3.1 · about 20 min

Random variables and distributions

A random variable is a number decided by chance; its distribution lists what values it can take and how likely each is. Discrete and continuous, probability mass and density, and the mean and variance of a distribution.

Key points, meanings and formulas on one page: choose "Save as PDF" in the print box.

Module 3 · about 20 minutes · school maths. You’ll be able to say what a random variable and its distribution are, tell discrete from continuous, and compute the mean and variance of a simple distribution.

A random variable is a number that chance decides, and its distribution is the full list of what it can be and how often.

In everyday terms: before a customer walks in, the number of items they will buy is unknown, but not unknowable: from experience, 40 % buy one, 30 % two, and so on. That table of chances is the distribution.

1. Numbers decided by chance

A random variable is a number whose value depends on chance: the number of orders in the next hour, tomorrow’s sales, whether the next visitor buys (1) or not (0), how long the next call lasts. Before it happens, you can’t know the value, but you can describe which values are possible and how likely each one is. That description is the variable’s distribution.

Distributions are the backbone of the rest of the course. A test (Module 6) asks “how likely is this result if nothing changed?”, which needs the distribution of the result when nothing changed.

2. Discrete and continuous

  • Discrete variables take separate values, usually counts: items in a basket, complaints per day, a yes/no outcome. Their distribution is a probability mass function (PMF): a probability for each value, and they add up to 1.
  • Continuous variables can take any value in a range: time, weight, revenue (near enough). Any single exact value has probability 0, so we use a probability density function (PDF), a curve whose area over an interval is the probability of landing in it. The total area is 1.

The cumulative distribution function (CDF), F(x)=P(X≤x), works for both: the chance of being at or below x. Percentiles (Lesson 1.5) are read off the CDF.

Try it: roll and add dice
rolls
average total so far
expected total E[X] = 3.5 × dice
The total of the dice is a random variable: a number decided by chance. Its distribution lists every possible value with its probability (the dots, worked out exactly by counting). Rolled bars are the same thing estimated from experience. With one die every face is equally likely; with two, 7 is the most common total because more combinations make it.

The dots are the exact PMF of the dice total, found by counting combinations. The bars are what you get by rolling. With more rolls, the bars match the dots: a distribution is what the data would look like in the long run.

3. The mean and variance of a distribution

A distribution has its own mean (expected value, Lesson 2.3) and variance:

μ=E[X]=∑xxP(X=x)σ2=Var(X)=∑x(x−μ)2P(X=x)

For continuous variables the sums become integrals, but the meaning is the same: the long-run average and the long-run spread.

Two rules analysts use all the time, for independent variables X and Y and constants a, b:

E[aX+b]=aE[X]+bVar(aX+b)=a2Var(X)
E[X+Y]=E[X]+E[Y]Var(X+Y)=Var(X)+Var(Y)

Variances add for independent variables, standard deviations do not. That is why the spread of a sum or average grows more slowly than you might expect, the key to Module 4.

X
The random variable: the number we will see, such as items in the next basket.
P(X = x)
For counts: the chance of exactly x. All of them add up to 1.
Density f(x)
For measurements: probability is the area under the curve between two values, not the height.
μ = Σ x·P(x)
The mean of the distribution: the long-run average of X.
σ² = Σ (x − μ)²·P(x)
The variance of the distribution: the long-run average squared distance from μ.
Physical meaning
A distribution is a recipe for data. Your real data are one batch cooked from it; statistics works backwards from the batch to guess the recipe.

“A density of 2 means a 200 % chance.” For a continuous measurement, the height of the curve is not a probability. Only areas are. A narrow curve can be taller than 1 as long as its total area is 1.

Watch it happen, one step at a time:

The table. Items per basket: 1 (40 %), 2 (30 %), 3 (20 %), 4 (10 %).
Check it adds to 1. 0.4 + 0.3 + 0.2 + 0.1 = 1. ✓
Mean. 1 × 0.4 + 2 × 0.3 + 3 × 0.2 + 4 × 0.1 = 2.0 items.
Squared gaps, weighted. (1−2)² × 0.4 + 0 × 0.3 + (3−2)² × 0.2 + (4−2)² × 0.1 = 0.4 + 0 + 0.2 + 0.4 = 1.0.
SD. √1.0 = 1 item. A typical basket is 2 items, give or take 1.
Maths and principle

Principle: a distribution is the long-run pattern of a chance quantity; data is a sample from it.

Equations: PMF P(X=x), PDF f(x) with P(a≤X≤b)=∫abf(x)dx, CDF F(x)=P(X≤x). Mean ∑xP(x); variance ∑(x−μ)2P(x).

Try it: one die has mean 3.5 and variance 35/12 ≈ 2.92. What are the mean and variance of the total of 2 dice? (7 and 5.83: both double, because they add for independent dice.) The SD goes from 1.71 to 2.42, up only by √2.

4. Worked example

Made-up numbers. Basket sizes at a corner shop:

Items x 1 2 3 4
P(X = x) 0.4 0.3 0.2 0.1
  • Check: 0.4 + 0.3 + 0.2 + 0.1 = 1. ✓
  • Mean: 1(0.4) + 2(0.3) + 3(0.2) + 4(0.1) = 0.4 + 0.6 + 0.6 + 0.4 = 2 items.
  • Variance: (1−2)²(0.4) + 0²(0.3) + 1²(0.2) + 2²(0.1) = 0.4 + 0 + 0.2 + 0.4 = 1.0; SD = 1 item.
  • CDF at 2: P(X ≤ 2) = 0.7, so 70 % of baskets have 2 items or fewer.
  • If items cost $3 each plus a $1 bag fee: E[3X + 1] = 3(2) + 1 = $7, SD = 3 × 1 = $3.

5. Practice

  1. Is “number of website errors today” discrete or continuous? “Server response time”?
  2. P(X = 0) = 0.5, P(X = 10) = 0.5. Find the mean and SD.
  3. Daily sales have mean $2,000 and SD $300, independent across days. What are the mean and SD of a 4-day total?
Answers
  1. Discrete (a count); continuous (a time).
  2. Mean 5; variance 0.5(25) + 0.5(25) = 25; SD 5.
  3. Mean $8,000. Variance 4 × 300² = 360,000, SD $600 (not $1,200).

Try it on your own data: the probability distribution explorer draws the PMF, PDF and CDF of the common distributions and reads probabilities off them.

New words: random variable, distribution, discrete, continuous, probability mass function, probability density function, cumulative distribution function.

  • A random variable is a number decided by chance; its distribution lists values and chances.
  • Discrete variables have probabilities for each value; continuous ones have densities, and areas are probabilities.
  • Mean of a distribution: Σ x·P(x). Variance: Σ (x − μ)²·P(x).
  • Data are a sample from a distribution; statistics guesses the distribution from the data.

Check yourself

1Which of these is a continuous random variable?
2For a continuous distribution, what gives the probability of a value between 10 and 20?
3A die is rolled. What is E[X], the expected value of the face?

Sources

Your ticks stay in this browser. Save them as a file on the course home.

Updated 2026-11-22. Numbers in the examples are made up to show the idea unless a source is given. Simulations run in your browser; nothing you type is sent anywhere.