A

**random variable** maps outcomes from a sample space to numbers, making the outcomes easier to manipulate. For example, there isn’t much to be done with outcomes from the coin-flip sample space {

*H*,

*T* }, but mapping outcomes to integers with the random variable

*X* = { (

*H*, 0), (

*T*,1) } allows mathematical manipulations. The mapping used depends on what’s being done.

*X*'s previous definition might be useful when counting the number of tails, while the definition

*X* = { (

*H*, 1), (

*T*, -1) } is more suited for keeping track of wins and losses.

Given a random variable

*X* over a sample space, the probability that

*X*equals a particular value

*k* is the sum of the probabilities of the outcomes that

*X* maps to

*k*: \[Pr(X = k) = \sum_{X(o) = k} Pr(o) \] For example, let the random variable

*X* map the outcome

*i* of a single die roll to

*i*. The probability that

*X* is even is \[ Pr(even(X)) = Pr(2)+ Pr(4) + Pr(6) = 1/6 + 1/6 + 1/6 = 1/2\]Computing the

**mean** (or

**average** or

**expected value**) of a random value is a common mathematical manipulation. A random variable’s mean is the sum of the values in the range, with each value weighted by its probability: \[ \sum_{k\in range(X)} kPr(X = k) \] The mean is often represented by \(\mu\). To continue the die-roll example,

*X*'s mean is

\[ \begin{eqnarray}

& & 1Pr(X = 1) + 2Pr(X = 2) + \cdots + 6Pr(X = 6) \\

&=& 1\cdot1/6 + 2\cdot1/6 + \cdots + 6\cdot1/6 \\

&=& (1 + 2 + \cdots + 6)1/6 \\

&=& 21\cdot1/6 \\

&=& 3.5

\end{eqnarray} \]A random variable’s mean is not necessarily a member of its range.