📘 CodingMarble Learn

Random Variables and Probability Distributions

A random variable X gives a number to every outcome of a chance experiment. A discrete random variable takes separate values; its probability distribution lists each value x with its probability P(X = x), and these add up to 1. The mean (expected value) is E(X) = Σ x·P(x). The variance Var(X) = E(X²) − [E(X)]² measures spread, and the standard deviation is its square root.

🎬 Step-by-step story

  1. Toss 3 coins. There are 8 possible outcomes, like HHT or TTT. Each block is one outcome.
  2. Now count the heads in each outcome. This count is a random variable, X. The blocks sort themselves into columns 0, 1, 2 and 3.
  3. Divide each column by 8. That gives the probability of each value. The list of values and probabilities is the probability distribution. It adds up to 1.
  4. Multiply each value by its probability and add. You get the mean, E(X) = 1.5. The red triangle shows where the bars balance.
  5. Values do not all sit at the mean. Variance measures how far they spread. Here it is 0.75, so the standard deviation is about 0.87.
  6. Your turn. Change the number of coins and the chance of a head. Watch the bars change and the balance point move to n × p.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Is a random variable really a variable, or a function?

It is really a function (a rule): input an outcome, output a number. In step 2 each block (outcome) gets one number, its count of heads.

Why must the probabilities add to exactly 1?

Every outcome lands in exactly one column, so the columns together hold all 8 of 8 outcomes. 8/8 = 1. See step 3.

Why is the mean called the balance point?

If the bars were weights on a seesaw, the seesaw would balance exactly at E(X). In step 4 the red triangle sits at 1.5 and the bars are equal on both sides.

Why do we square the distances in variance?

Distances below the mean are negative and above are positive, so plain distances would cancel to 0. Squaring makes them all positive. The purple bar in step 5 shows one SD on each side.

What happens to the mean if the coin is biased?

The bars lean toward more heads and the balance point moves to n × p. In free play set p = 0.8 and watch the triangle move right.

How is a continuous random variable different?

It can take any value in a range, so instead of bars we draw a smooth curve and use area as probability. In free play, raise n to 8: the bars already start to look like a smooth hill.

What is a random variable?

A chance experiment is something whose result you cannot know in advance, like tossing coins or rolling a die.

A random variable is a rule that turns each outcome into a number. We write it with a capital letter, like X.

Example: toss 3 coins and let X = number of heads. The outcome HTH gives X = 2. The outcome TTT gives X = 0.

It is called "random" because its value depends on chance, and "variable" because it can take different values.

Discrete and continuous random variables

A discrete random variable takes separate values you can list: number of heads, number of goals, number of defective bulbs in a box.

A continuous random variable can take any value in a range: height of a student, time to finish a race, mass of a mango.

For a continuous variable we do not give the chance of one exact value (that is 0). Instead a curve called the probability density function f(x) is drawn, and the area under the curve between two values is the probability. The total area under the curve is 1.

Probability distribution

A probability distribution is a table (or graph) of every value x with its probability P(X = x).

For 3 coins: x = 0, 1, 2, 3 with P = 1/8, 3/8, 3/8, 1/8.

Two rules must always hold:

You can use these rules to find a missing value. If P(X = x) = k, 2k, 3k, 4k, then 10k = 1, so k = 0.1.

The cumulative probability P(X ≤ x) adds up all probabilities up to x.

Expected value (mean)

The expected value or mean is the average result you would get if you repeated the experiment a very large number of times.

E(X) = Σ x · P(X = x). Multiply each value by its probability and add.

For 3 coins: E(X) = 0·1/8 + 1·3/8 + 2·3/8 + 3·1/8 = 12/8 = 1.5.

E(X) need not be a value X can actually take. You never see 1.5 heads, but over many tosses the average is 1.5.

Useful rules: E(aX + b) = a·E(X) + b, and for two variables E(X + Y) = E(X) + E(Y).

Variance and standard deviation

Variance measures spread: how far values usually are from the mean.

Var(X) = E(X²) − [E(X)]², where E(X²) = Σ x² · P(x).

The standard deviation σ = √Var(X) is in the same units as X.

For 3 coins: E(X²) = 0 + 3/8 + 12/8 + 9/8 = 3, so Var = 3 − 2.25 = 0.75 and σ ≈ 0.87.

Rules: Var(aX + b) = a²·Var(X) (adding b does not change the spread). If X and Y are independent, Var(X + Y) = Var(X) + Var(Y).

For n independent tries each with success chance p (a binomial variable), E(X) = np and Var(X) = np(1 − p).

Using expected value to make decisions

A game is fair if your expected gain is 0.

Example: you pay ₹20 to roll a die. You win ₹60 on a six, nothing otherwise. Expected gain = 60 × 1/6 − 20 = 10 − 20 = −₹10 per game. On average you lose ₹10, so the game is not fair.

Companies compare the expected cost of choices, like whether to buy a warranty or which crop to plant, and pick the best expected value. But expected value is a long-run average; one single try can still go either way.

Try it: the coin table

Toss 3 coins 40 times. Each time write down how many heads you got. Make a tally for 0, 1, 2 and 3. Divide each tally by 40. Your fractions should be close to 0.125, 0.375, 0.375 and 0.125. Now add up all 40 results and divide by 40. The answer should be near 1.5, the expected value. Check it against step 4 of the 3D.

Key formulas and definitions

Worked examples

1. Two coins are tossed. X = number of tails. Write the probability distribution.

Outcomes: HH, HT, TH, TT. X = 0 (HH), 1 (HT, TH), 2 (TT). So P(0) = 1/4, P(1) = 2/4 = 1/2, P(2) = 1/4. Check: 1/4 + 1/2 + 1/4 = 1.

2. P(X = x) is 0.1, k, 0.3, 2k for x = 0, 1, 2, 3. Find k.

All add to 1: 0.1 + k + 0.3 + 2k = 1 → 3k = 0.6 → k = 0.2.

3. A fair die is rolled. Find E(X), where X is the number shown.

Each face has probability 1/6. E(X) = (1 + 2 + 3 + 4 + 5 + 6)/6 = 21/6 = 3.5.

4. Find the variance of the die score.

E(X²) = (1 + 4 + 9 + 16 + 25 + 36)/6 = 91/6 ≈ 15.17. Var = 91/6 − 3.5² = 15.17 − 12.25 ≈ 2.92. σ ≈ 1.71.

5. X has P(0) = 0.2, P(1) = 0.5, P(2) = 0.3. Find E(X), Var(X) and E(3X + 2).

E(X) = 0 + 0.5 + 0.6 = 1.1. E(X²) = 0 + 0.5 + 1.2 = 1.7. Var = 1.7 − 1.21 = 0.49. E(3X + 2) = 3 × 1.1 + 2 = 5.3.

6. A raffle sells 500 tickets at ₹50. One prize is ₹10 000 and two prizes are ₹2 500. Find the expected gain of one ticket.

Expected winnings = 10 000 × 1/500 + 2 500 × 2/500 = 20 + 10 = ₹30. Expected gain = 30 − 50 = −₹20. On average a buyer loses ₹20.

7. A basketball player scores a free throw with probability 0.8. She takes 10 throws. Find the mean and SD of the number scored.

This is binomial with n = 10, p = 0.8. E(X) = 10 × 0.8 = 8. Var = 10 × 0.8 × 0.2 = 1.6. σ = √1.6 ≈ 1.26.

Common mistakes

Practice quiz

1. A random variable is:
2. In any probability distribution the probabilities add up to:
3. For a fair die, E(X) =
4. Which is a continuous random variable?
5. If Var(X) = 4, then Var(3X + 1) =

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a random variable in simple words?

It is a number that depends on chance, like the number of heads when you toss coins. Each possible outcome gets a number.

How do you find the expected value?

Multiply each value of X by its probability and add all the products: E(X) = Σ x·P(x).

What is the difference between variance and standard deviation?

Both measure spread. Variance is in squared units; standard deviation is its square root, so it is in the same units as X.

Where this is taught

NetherlandsVWO 4 (bovenbouw, 2e fase)Probability and statistics (part 1)
CBSE (India)Class 12Probability Distributions
England (GCSE, A level)Year 12Optional application 2 Statistics (part 1)
England (GCSE, A level)Year 13Optional application 2 Statistics (part 2)
USA (Common Core, NGSS, AP)Grade 10Applications of probability
USA (Common Core, NGSS, AP)Grade 10Applications of probability
USA (Common Core, NGSS, AP)Grade 11Inferences and conclusions from data
USA (Common Core, NGSS, AP)Grade 11Inferences and conclusions from data
USA (Common Core, NGSS, AP)Grade 12Probability, Random Variables, and Probability Distributions
USA (Common Core, NGSS, AP)Grade 12Probability for decisions
South Korea고등학교 2학년Statistics
South Korea고등학교 3학년Statistics
FrancePremièreProbability and statistics
FranceTerminaleProbability
Russia9 классRandom variables
Russia10 классRandom variables
Russia10 классRandom variables
Russia11 классRandom variables
China高三Ch.7 Random variables

Learn first

Related lessons

All Maths lessons