Random variable

A random variable is used in mathematics to study probability theory. It was developed to model the chance of events happening in all kinds of real-life scenarios.
Definition.
Take two measurable spaces, and name them formula_1 and formula_2. A measurable space is any pair of sets, called formula_3 and formula_4, that follow these rules:
A random variable, named formula_11, is a measurable function from formula_12 to formula_13. This is written formula_14. A random variable is typically represented by capital roman letters such as formula_15, formula_16, formula_17 and formula_18, and can be either discrete (taking on a countable set of values) or continuous (taking on an interval of values).
The set formula_12 is called the sample space. The set formula_20 is called the event space.
Use in Probability.
Take a probability measure formula_21 on formula_1. Take a set formula_23 in formula_24. Then formula_25 is defined to mean formula_26.
Examples with Dice.
When you roll a dice, 6 events can happen. These events are the different numbers that can show on the dice: 1, 2, 3, 4, 5, or 6. 
Dicing Fruit.
Here is an example of a random variable. You roll a fair dice once. If the number on the dice is odd, you eat an apple, and if the number is even, you eat an orange. The random variable is the type of fruit that you will eat. Before you roll the dice, you don't know if you will eat an apple or an orange. We can also write this with mathematics:
Take formula_27. Take formula_20 to be the power set of formula_12. Take formula_30. Take formula_24 to be the power set of formula_13. Our random variable follows the even/odd rule from above:
Here formula_34 represents the number on the dice after you roll it. We said the dice is fair. In mathematics, this means formula_35 for formula_36 and formula_37.
The event that you eat an apple is a set in the event space. It is formula_38. The probability that you eat an apple is the probability measure of this set. It is formula_39.
Dicing Fruit Unfairly.
Here is another example. Sometimes a dice is unbalanced. This means that it rolls some numbers more often than others. We can do the same experiment as above, but with an unbalanced dice.
For example, let's say that we use a dice that has been changed in one way: it never rolls the number 5. Then you are less likely to eat an apple, because 5 is an odd number. The random variable is "exactly" the same as before:
This is because end possibilities have not changed. After the dice is rolled, you will eat an apple or an orange. You don't know which. What has changed is the "probability" that you eat an apple or an orange. In mathematics, this means
The event that you eat an apple is "the same set" as for the fair dice. It is formula_38. But this event is now less likely to happen, because the dice cannot roll a 5. In other words, the probability that you eat an apple is "different" than for the fair dice. It is formula_43.
Probability spaces.
The examples show that a random variable doesn't automatically give probabilities. If we choose formula_44 differently, one random variable can give different probabilities. This can be confusing. For this reason, mathematicians often define a random variable on a probability space. The mathematical notation for this is formula_45. This fixes the probability measure. Then there is no confusion about the probabilities of events.