# Random Variables as Functions: Spinner Lab

A random variable is a function of the outcome: spin a pointer, read a number off it and watch the law of X appear as arc lengths. Interactive lab.

## About this tool

A random variable is an ordinary function of the outcome. The only randomness is the outcome itself, here the angle where a spinner stops. The variable reads a number off it, such as the height of the point on the rim or the place where a beam from the pointer hits a wall. Asking whether X lies in a set B is asking whether the spinner stopped on the matching arcs, so P(X in B) is an arc length. The law of X is the spinner's uniform measure carried over to the value axis.

## Frequently asked questions

### What is a random variable, really?

It is a function X from the outcomes Ω to the real numbers, with one technical requirement: for every set B of values you care about, the set of outcomes where X lies in B must be an event. Nothing about X is random once the outcome is fixed. Randomness comes only from which outcome occurs. Two variables can be very different functions and still have the same distribution.

### What is the law of X?

The law, or distribution, of X is the probability measure it creates on the real line: P(X in B) is the probability of the set of outcomes that X sends into B. It pushes the probability P forward through the function X. Once you know the law you can compute probabilities and expectations of X without going back to Ω. On the page, you pull a band of values back to arcs of the spinner and measure them.

### What should I try on the pages?

Spin the pointer, read the height of the point on the rim and compare the histogram with the arcsine law: the density piles up near the top and bottom, because the rim is steep there. Switch to the beam hitting a wall and you get the Cauchy law, whose tails are so heavy that it has no mean. On the second page, read probabilities off the distribution function F(x) = P(X ≤ x), where jumps are atoms.

### If two variables have the same law, are they equal?

No. The sine and the cosine of the spinner angle have exactly the same law, yet they take different values at almost every outcome. The law only records how likely each set of values is, not which outcomes produce them. Equality in law is much weaker than equality as functions, which is why the joint behaviour, not just the individual laws, matters for sums and products.

## Learn the theory

- [Random variables and their distributions](https://quantsandbox.dev/guide/probability/random-variable-distributions): Random variables as measurable functions and the distributions they carry: distribution functions, atoms and densities, common laws, quantiles, sampling.
- [Measurable functions](https://quantsandbox.dev/guide/probability/measurable-functions): Functions whose level sets can be measured: preimages, the half-line test, closure under limits, simple functions, σ(f) and the image measure.
- [Probability spaces, σ-algebras and random variables](https://quantsandbox.dev/guide/stochastic/probability-spaces): Sample space, σ-algebra, probability measure, measurable maps and the σ-algebra generated by a variable.
- [The law of large numbers and the central limit theorem](https://quantsandbox.dev/guide/stochastic/law-of-large-numbers-clt): Why averages settle down, how fast, and why the normal distribution appears: the two theorems behind Monte Carlo and the Brownian limit.

Open the interactive tool: https://quantsandbox.dev/random-variables
