Random Variables
Numbers from chance.
A random variable is a number whose value comes from chance. The number you roll on a die. The number of customers tomorrow. A person's height. We usually write it with a capital letter, like X.

- A number from chance
- Die rolls, customers, heights
- Written as X
Two kinds
Discrete random variables take separate values you can count, like zero, one, two customers. Continuous random variables can take any value in a range, like a height of one seventy point three one centimetres. The kind decides which distribution we use to describe it.
Discrete
- countable valuesdie rolls, customersprobability of each value
Continuous
- any value in a rangeheight, time, priceprobability of a range
A distribution is a table of chances
For a fair die, the distribution is simple. Each value, one to six, has a probability of one sixth. The probabilities of all values must add up to one. Run it. A distribution tells you every possible value, and how likely it is.
from fractions import Fraction
die = {face: Fraction(1, 6) for face in range(1, 7)}
for face, p in die.items():
print(face, p)
print("total:", sum(die.values()))1 1/6 2 1/6 3 1/6 4 1/6 5 1/6 6 1/6 total: 1
Summary
A random variable is a number from chance, either discrete or continuous. Its distribution lists the values and their probabilities. Next, the expected value.
Key takeaways- X is a number from chance
- Discrete or continuous
- Probabilities add to 1