Sub topic 4
Variance: how swingy a choice feels
This chapter assumes you have read the previous chapters on outcomes, stakes, and expected value. You should be able to compute a probability-weighted average and read short Python functions. Expected value tells you what a gamble is worth on average. Variance tells you how far the results stray from that average, and that spread is what the player feels.
What variance measures
Take two options with similar averages:
- Safe: always pays 10.
- Risky: pays 25 half the time and loses 2 half the time.
The expected values are 10 and 11.5, which is a small gap. The experience is very different. The safe option never surprises anyone. The risky option produces a big win or a small loss, and nothing in between.
Variance is the probability-weighted average of the squared distance between each outcome and the expected value:
Var = Σ p × (v − mean)²
Squaring does two things. It stops positive and negative deviations from cancelling out, and it penalizes large deviations more than small ones. The cost is that variance is in squared units (points²). Standard deviation is the square root of variance and is back in ordinary points. Use it when you describe a result to other people.
import math
def expected_value(outcomes):
# outcomes: list of (probability, value) pairs whose probabilities sum to 1
return sum(p * v for p, v in outcomes)
def variance(outcomes):
mean = expected_value(outcomes)
return sum(p * (v - mean) ** 2 for p, v in outcomes)
def std_dev(outcomes):
return math.sqrt(variance(outcomes))
safe = [(1.0, 10)]
risky = [(0.5, 25), (0.5, -2)]
print(variance(safe)) # 0.0
print(variance(risky)) # 182.25
print(std_dev(risky)) # 13.5Each risky outcome sits 13.5 points from the mean of 11.5, so the standard deviation is 13.5. A typical result of the risky option lands about 13.5 points away from its average. That is larger than the average itself, which is why the option feels wild.
Variance as a design dial
Designers can change variance without changing expected value. Two payout tables with the same average can feel completely different.
| Option | Outcomes | Expected value | Variance |
|---|---|---|---|
| Steady | 10 always | 10 | 0 |
| Mild | 8 or 12, equal odds | 10 | 4 |
| Swingy | 0 or 20, equal odds | 10 | 100 |
All three have the same expected value, so a player who only compares averages sees no difference. The player still has a real preference, and that preference is the decision you want them to make.
Variance shrinks with repetition, but only relatively
A single decision and a hundred repeated decisions behave differently. If you add up n independent plays of the same gamble:
- The total's expected value grows by a factor of n.
- The total's variance grows by a factor of n.
- The total's standard deviation grows only by a factor of √n.
So the average per play has standard deviation sd / √n. Luck matters less per play as plays accumulate. This is the law of large numbers working for you.
import math
sd = 13.5 # standard deviation of the risky option
print("plays sd_of_average sd_of_total")
for n in (1, 4, 9, 25, 100):
print(n, round(sd / math.sqrt(n), 2), round(sd * math.sqrt(n), 2))
# 1 13.5 13.5
# 4 6.75 27.0
# 9 4.5 40.5
# 25 2.7 67.5
# 100 1.35 135.0The total gets noisier in absolute terms (13.5 to 135), but the noise per play falls (13.5 to 1.35). Over 100 plays, the risky option's 1.5-point edge per play adds up to about 150 points, which is bigger than one standard deviation of the total (135). That means the better option usually wins, though not always.
You can check this by simulation:
import random
def total(outcomes, plays, rng):
probs = [p for p, _ in outcomes]
values = [v for _, v in outcomes]
return sum(rng.choices(values, weights=probs, k=plays))
def risky_beats_safe(plays, trials=20_000, seed=7):
rng = random.Random(seed)
safe = [(1.0, 10)]
risky = [(0.5, 25), (0.5, -2)]
wins = sum(total(risky, plays, rng) > total(safe, plays, rng)
for _ in range(trials))
return wins / trials
for plays in (1, 10, 100):
print(plays, risky_beats_safe(plays))
# roughly 0.50, 0.62, 0.86The exact values, from the binomial distribution, are 0.50, 0.62, and 0.86. Your simulated numbers will differ by a small amount of sampling noise.
This has a direct consequence for game length. In a game with many small risk decisions, the better average strategy wins reliably. In a game with a few big ones, the winner is mostly decided by luck. Short games and single-elimination formats need lower variance per decision if you want skill to show.
Who benefits from high variance
High variance helps the player who is behind, because they need an unlikely result. It hurts the player who is ahead, because it threatens a lead they could have kept with steady play. Designers use this in several ways:
- Give trailing players access to high-variance options, such as a long-shot attack or a rare card. This acts as a comeback mechanism without a direct bonus.
- Make the leader's best options low-variance, so a lead is worth holding.
- Limit variance in the early game, where a bad swing can eliminate a player before they have made a meaningful choice.
Limits of variance as a number
Variance is one number, and it throws away the shape of the distribution. Two gambles can have identical expected value and variance and still feel different, and a gamble with a very different shape can still be matched on variance by accident.
Consider a lottery-style option: 1% chance to win 1000, otherwise nothing.
def expected_value(outcomes):
return sum(p * v for p, v in outcomes)
def variance(outcomes):
mean = expected_value(outcomes)
return sum(p * (v - mean) ** 2 for p, v in outcomes)
lottery = [(0.01, 1000), (0.99, 0)]
print(expected_value(lottery)) # 10.0
print(variance(lottery)) # 9900.0 (floating-point output may differ in the last digits)The expected value is 10, the same as the safe option. The variance is 9900. The more important fact is that 99% of the time the player gets nothing. The average is carried entirely by a rare event. This is a skewed or heavy-tailed distribution. Variance alone suggests a big spread. It does not tell you that the typical experience is a loss.
Keep these limits in mind:
- Typical vs. average. For skewed gambles, check the median or the probability of the most common result as well as the mean.
- Rare events need sample size. A 1% jackpot may never appear in a short session. Players can finish a whole game without seeing the thing that justifies the expected value.
- Variance is symmetric. It treats a large gain and a large loss as equally "spread". Players do not feel them equally, which later chapters cover under risk perception and loss aversion.
- Stakes change feel. The same variance on a trivial reward and on a game-ending loss produces very different tension. Variance is measured in outcome units, so always read it together with what the outcomes mean to the player.
Common errors
- Probabilities that do not sum to 1.
variancewill return a plausible-looking but wrong number. Add an assertion when you build outcome tables. - Comparing variances across different scales. Variance of 100 means something different when the mean is 10 than when it is 10,000. Divide the standard deviation by the mean (the coefficient of variation) when you need a scale-free comparison, and only when the mean is positive and not near zero.
- Assuming independence. The √n rule applies to independent plays. If one outcome changes the odds of the next, such as a streak bonus or a shared deck, the total's variance is different.
- Reading a mean as a promise. An expected value of 11.5 never occurs as a single result of the risky gamble. Only the spread tells the player what will happen.
Exercises
Exercise
Gamble A pays 6 with probability 0.5 and 0 otherwise. Gamble B always pays 3. What are the expected values and variances of both, and which one feels swingier?
Show answer
Both have an expected value of 3. Gamble B has variance 0. Gamble A has variance 0.5 × (6 − 3)² + 0.5 × (0 − 3)² = 4.5 + 4.5 = 9, so its standard deviation is 3. Gamble A feels swingier.
Exercise
A designer wants a risky option to beat a safe option reliably in a game with only 3 decisions. Why does the √n rule suggest that this will be hard, and what could the designer change?
Show answer
With only 3 plays, the standard deviation of the total is about 1.7 times a single play's (√3) while the advantage grows only 3 times, so luck still has a large effect on who wins. The designer could reduce the risky option's variance, raise its expected value gap, or add more decisions per game so the advantage can show through.