Random variables (discrete vs continuous)
Log in to access the full course.
What is a random variable?
A random variable is a variable whose value is determined by a random process. Rather than having a fixed value, it takes on different values with certain probabilities.
Think of rolling a die. Before you roll, the outcome is uncertain — it could be 1, 2, 3, 4, 5, or 6. A random variable represents that uncertain outcome. We write to mean "the probability that the die lands on 3."
Random variables come in two types: discrete and continuous.
Discrete random variables
A discrete random variable takes on a countable set of values — usually whole numbers.
Examples:
- The number of heads in 3 coin flips:
- The number of customers arriving in an hour:
- The result of rolling a die:
For a discrete random variable, we describe its behavior with a probability mass function (PMF): a list of probabilities for each possible value. The probabilities must sum to 1:
Example — fair die:
| 1 | 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
Continuous random variables
A continuous random variable can take any value within a range — not just whole numbers.
Examples:
- A person's height: any value in, say, metres
- The time until the next bus arrives: any value
- The temperature at noon tomorrow
Because there are infinitely many possible values, the probability of any single exact value is zero: . Instead, we talk about probability over intervals.
For continuous random variables we use a probability density function (PDF) . The probability that falls between and is the area under the curve:
The total area under the PDF equals 1:
Expected value
For both types, the expected value is the long-run average — the value you would expect on average over many repetitions.
For a discrete variable:
For the fair die:
Quick comparison
| Discrete | Continuous | |
|---|---|---|
| Values | Countable (often integers) | Any value in a range |
| Probabilities described by | PMF | |
| Can be non-zero | Always zero | |
| Example | Die roll, coin flips | Height, temperature |