# Random variable

A random variable in probability and statistics is described as a variable in which the values of the variable are dependent on the outcomes of a random phenomenon or experiment. Random variables can take on a set of different possible values, each of which has a certain probability of occuring. Random variables are different from the type of variable used in algebra, and can be thought of as a way to map the potential outcomes of a random phenomenon.

A random event happens by chance; it is unpredictable. For example, whether a tossed coin lands on "heads" or "tails" is random. It's also possible for the penny to land on its side, but these events are not considered. Random variables allow us to quantify the outcomes of tossing a coin by assigning values to the outcomes. We only consider 2 outcomes of the coin toss, heads or tails, so we can use the numbers 1 and 0 to represent these outcomes and define a random variable, X, as:

The random variable X can take on the value of 1 if the coin lands on tails, or 0 if the coin lands on heads, with a probability of 50% of either occuring in a given toss of the coin. The values that X (1 and 0 in this case) can take on are referred to as the sample space, which can be denoted as {0, 1}. If we then wanted to write the probability of the coin landing on heads, we could write P(X = 0). For tails it would be P(X = 1). Using random variables allows us to efficiently write expressions and perform calculations by quantifying random events, rather than having to write out something like "the probability of a coin landing on heads when flipped one time." A coin flip is a relatively simple example of a random event. As the events we want to study get more complex, the use of random variables becomes even more useful.

## Discrete vs continuous random variables

A discrete random variable is a variable that can only take on certain exact values; they can either take on a finite number of distinct values, or a countably infinite set of values, like the integers. Another example of a discrete random variable is the possible values from the roll of a 6-sided die (1, 2, 3, 4, 5, 6).

In contrast, a continuous random variable takes on all values in a given interval. For example, given the interval [1, 5], a continuous random variable includes all real numbers (1.001, 2.889000015, 4) not just integer values. There are an infinite number of possibilities when considering continuous random variables. Examples of continuous random variables include human height and weight. While there is a certain range within which these measurements fall, within that range, there are an infinite number of possible height and weight measurements.