A random variable X is a function defined on a sample space S into the real numbers R, such that the inverse image of every point, subset or interval of R is an event in S (Definition 11.1). It turns the outcomes of a random experiment — which need not themselves be numbers, e.g. a coin's head/tail — into numbers we can compute with. Capital letters X,Y,Z denote the random variable itself; small letters x,y,z denote its possible values. If x is a possible value, its inverse image X−1(x)={ω∈S:X(ω)=x} is always an event of S, so it has a probability — this is what makes "P(X=x)" meaningful.
Two flavours are studied:
- Discrete random variable (Definition 11.2): its range is countable — finite, or a sequence x1,x2,x3,… — with every value carrying positive probability and the whole range's probabilities summing to 1. Used for counting a quantity: number of heads, number of defectives, a sum of dice faces, a winning amount taking finitely many values. A discrete random variable can even live on a continuous sample space (e.g. a step function of ω∈[0,20] taking only two values is still discrete, because its range, not its domain, is what is tested for countability).
- Continuous random variable (Definition 11.5): X:S→R takes any value in a set I⊆R, and P(X=x)=0 for every x∈I. Used for measuring a quantity: a lifetime, a waiting time, a distance from a centre — probability only accumulates over an interval, never at a single point.
Counting inverse images. For a discrete random variable built from a finite sample space, the standard technique is: (1) list/describe the full sample space S (or its size, via combinatorics); (2) work out every value X can take; (3) for each value, count how many sample points map to it — this count is the size of that value's inverse image, and dividing by ∣S∣ (when outcomes are equally likely) gives its probability. A quick check is that the inverse-image counts across all values of X must add up to ∣S∣.