🎲 πŸ“Š πŸ”’

Random Variables

Turning uncertainty into numbers we can work with β€” a visual, interactive guide

↓
Chapter 1

Why We Need This Tool

Imagine you're running a small coffee shop. Every morning, you wonder: how many customers will walk through the door today? Some days 50 people show up, other days 80, occasionally just 30. The outcome is uncertain β€” it varies randomly from day to day.

If you want to think clearly about this uncertainty, you need a way to connect what actually happens (the random comings and goings of customers) to numbers you can calculate with. You need to turn "a bunch of people showed up" into "47 customers arrived."

That's what a random variable does. It bridges the gap between uncertain real-world outcomes and numbers we can analyze.

β˜• Coffee Shop Day Simulator
Click "Simulate Day" to see how many customers arrive today

Each time you simulate a day, you get a different number β€” that's the randomness. But the rule (count total customers) stays the same. The random variable is the rule; the outcome is what changes.

Chapter 2

The Problem With Just Listing Outcomes

Suppose you're tracking the weather each day. Your sample space might include outcomes like "Sunny and warm," "Rainy and cold," or "Cloudy and warm." These descriptions are fine, but they're awkward to work with mathematically. You can't easily calculate averages with words.

What if instead you assigned a number to each outcome? That assignment β€” that systematic rule β€” is exactly what a random variable does.

🌦️ Weather Outcome Mapper
Click each weather outcome to see its assigned number β€” watch how multiple outcomes can share a value
β˜€οΈπŸ”₯
Sunny & warm
X = 3
β˜€οΈβ„οΈ
Sunny & cold
X = 2
🌧️πŸ”₯
Rainy & warm
X = 1
πŸŒ§οΈβ„οΈ
Rainy & cold
X = 0
☁️πŸ”₯
Cloudy & warm
X = 2
β˜οΈβ„οΈ
Cloudy & cold
X = 1

Notice that "Sunny and cold" and "Cloudy and warm" both map to X = 2. That's perfectly fine β€” a random variable assigns one number to each outcome, but different outcomes can share the same number.

Chapter 3

What Actually Is a Random Variable?

Here's the core idea: a random variable is a rule that assigns exactly one number to every possible outcome in your sample space. The rule is fixed β€” you decided ahead of time "X will count total customers." What varies is the outcome.

When we write X (using a capital letter), we're talking about this rule before we know what value it will have. We cannot say which outcome will occur, so we need to work with all possibilities at once.

πŸ”€ The Fixed Rule, Random Outcome
Click "Pick an Outcome" to see the same rule applied to different random outcomes
Rule: X = count total customers
The rule never changes. X always means "count total customers." But the number you get depends on which random outcome actually occurs.
Chapter 4

Why Such a Confusing Name?

The term "random variable" confuses almost everyone at first. It's not actually a variable in the algebra sense β€” and it's not the variable that's random, it's the outcome. The random variable itself is just a rule, a measurement procedure.

Think of a thermometer: it's a rule for assigning numbers to temperature. The thermometer isn't random. But tomorrow's temperature is uncertain, so the reading you'll see is also uncertain.

🌑️ The Thermometer Analogy
See how the three parts connect β€” the rule, the outcome, and the value
🌑️
The Rule
Thermometer (fixed)
β†’
🌀️
The Outcome
Tomorrow's weather (random)
β†’
72Β°
The Value
Reading (determined by outcome)

Maybe "uncertain numerical measurement" would be a better name, but we're stuck with "random variable." Just remember: it's the outcome that's random, not the rule.

Chapter 5

Connecting Back to Probability

Here's where random variables become really powerful. When you ask "What's the probability that X = 2?" you're really asking about a set of outcomes: "What's the probability the outcome is one where X equals 2?"

The random variable creates a bridge. On one side, messy complicated outcomes. On the other, clean numbers.

πŸŒ‰ Probability Bridge
Click a number value to see which outcomes produce it and calculate the probability
Example: P(X = 2) = ?
X = 2 when outcome is "Sunny & cold" OR "Cloudy & warm"
P(X = 2) = P(sunny & cold) + P(cloudy & warm)
Chapter 6

Two Fundamentally Different Types

Random variables come in two flavors. Discrete random variables take on separate, distinct values with gaps β€” think counting. Continuous random variables can take any value within an interval with no gaps β€” think measuring.

βš–οΈ Discrete vs. Continuous
Toggle between types to see examples of each

This distinction matters because we handle probability differently for these two types. For discrete, we can assign a probability to each individual value. For continuous, probability only makes sense for intervals.

Chapter 7

The Probability Mass Function

For discrete random variables, we organize probabilities using a probability mass function (PMF). Think of probability as physical mass concentrated at specific points β€” at X = 50, there's a mass of 0.40 probability.

πŸ“Š Coffee Shop PMF
Hover or click each bar to see the probability β€” notice the bars don't touch (gaps between values)
3040506070
PMF Rules:
1. Every probability is between 0 and 1
2. All probabilities add up to 1
Check: 0.10 + 0.20 + 0.40 + 0.20 + 0.10 = 1.00 βœ“
Why "mass"? Just like physical mass can be concentrated at specific points, probability mass sits at discrete locations with nothing in between.
Chapter 8

Why Individual Points Don't Work

Now think about measuring the time until your next customer arrives. This is continuous β€” it could be 1.5 minutes, 1.53 minutes, 1.537 minutes, and so on forever.

Here's a strange fact: for a continuous random variable, the probability of any exact value is zero. There are infinitely many possible times, so hitting any one exact value is infinitely unlikely.

πŸ” Zooming Into Infinity
Click "Zoom In" to see how there are always more values between any two points

For continuous random variables, probability only makes sense for intervals, not individual points. "Between 1 and 2 minutes" has real probability; "exactly 1.500000... minutes" does not.

Chapter 9

The Probability Density Function

Since we can't assign probability to individual points, we use a probability density function (PDF). A PDF is a curve, and probability comes from the area under that curve. The height is the density of probability, not the probability itself.

Think of it like a map showing population density. A dark region means many people per square mile, but the actual number of people depends on the area of the region, not just how dark it is.

πŸ“ˆ PDF Area Explorer
Drag the sliders to change the interval and see how the shaded area (probability) changes
2.0 min
4.0 min
The total area under the entire PDF must equal 1, because the probability that something happens is 100%.
Chapter 10

The Cumulative Distribution Function

The cumulative distribution function (CDF) works for both discrete and continuous random variables. It answers: "What's the probability that X is at or below a certain value?"

F(x) = P(X ≀ x)

Range formula:
P(a < X ≀ b) = F(b) βˆ’ F(a)
πŸ“Ά CDF Staircase Builder
Click each value to see probability accumulate step by step

Example: P(40 < X ≀ 60) = F(60) βˆ’ F(40) = 0.90 βˆ’ 0.30 = 0.60. So 60% of days have between 40 and 60 customers.

Chapter 11

Distributions: Patterns That Keep Appearing

As you study different random variables, you notice that certain probability patterns show up again and again. These named distributions are like templates β€” once you recognize that your situation matches one, you can use everything that's been figured out about it.

πŸ—‚οΈ Common Distribution Gallery
Click each distribution to see its shape and where it appears in real life

But not every random variable fits a named distribution. Your coffee shop customer count might have its own unique pattern. Think of distributions like recipes β€” some situations follow a standard recipe, others need a custom one. Both are valid random variables.

Chapter 12

When Two Things Vary Together

Often multiple uncertain quantities vary together. Suppose you track both the number of customers (X) and your total sales in dollars (Y) each day. These are two different random variables, but they're related β€” more customers usually means more sales.

A joint distribution shows the probability of different combinations.

πŸ”— Joint Distribution Table
Click a cell to see the probability of that specific customer-sales combination
Y = $300 Y = $400 Y = $500 Y = $600

Joint distributions let you ask questions like: "If I know I had 50 customers, what's the probability my sales exceeded $450?" This is incredibly useful for understanding how different uncertain quantities interact.

Chapter 13

Bringing It All Together

Random variables are a tool for working with uncertainty in a structured way. They translate messy, uncertain outcomes into numbers we can analyze mathematically.

πŸ—ΊοΈ The Process at a Glance
Click each step to reveal more detail

By defining X as the number of customers and figuring out its PMF, you can answer questions like "What's the probability of a slow day?" or "What's my most likely customer count?" These questions help you make real decisions β€” how much coffee to prepare, how many staff to schedule.

Random variables turn vague uncertainty into precise probability. They're the foundation of statistics, data science, and any field that deals with uncertain information.

Your Toolkit

πŸ”’
Random Variable
A rule that assigns a number to every outcome
πŸ“Š
PMF
Probability mass at each discrete value
πŸ“ˆ
PDF
Probability density curve β€” area = probability
πŸ“Ά
CDF
Cumulative probability up to a value
πŸ—‚οΈ
Distributions
Named patterns like normal and uniform
πŸ”—
Joint Distribution
How multiple random variables vary together

Cite this post

Rizvi, I. (2026). Random Variables β€” A Visual Guide. theog.dev.
DOI: 10.5281/zenodo.19413293

@article{rizvi2026randomvariables,
  title   = {Random Variables β€” A Visual Guide},
  author  = {Rizvi, Imran},
  year    = {2026},
  url     = {https://theog.dev/ml-ds/random-variables-visual.html},
  doi     = {10.5281/zenodo.19413293}
}