Sub topic 6
Variance and streaks: why short runs feel unfair
This chapter assumes you have read the earlier chapters on probability basics, expected value, and distributions. You should be comfortable with an expected value as a long-run average, and with reading short Python programs.
Expected value is not what players experience
Expected value tells you what a random event pays on average. Players never experience the average. They experience a short sequence of outcomes, and a short sequence can sit far from the average for a long time.
The measure of that spread is variance. Variance is the average squared distance between an outcome and the expected value. Its square root is the standard deviation, which is in the same units as the outcome and is easier to read.
For a fair six-sided die the expected value is 3.5. You can compute the variance directly:
import statistics
faces = [1, 2, 3, 4, 5, 6]
print(statistics.mean(faces)) # 3.5
print(statistics.pvariance(faces)) # 2.9166...
print(statistics.pstdev(faces)) # 1.7078...A typical single roll lands about 1.7 away from 3.5. That is almost half the mean, so one roll tells you very little about the average.
How spread shrinks with sample size
When you add up independent rolls, the spread of the total grows with the square root of the number of rolls. The spread of the average shrinks by the same factor. For the die, the standard deviation of the average of n rolls is 1.71 divided by the square root of n.
Two consequences matter for design:
- Halving the noise costs four times as many trials. Averages converge slowly.
- A typical play session is short. A player who opens 20 packs or fights 30 battles is living on the left side of the chart.
Streaks are normal in random data
A streak is a run of identical outcomes. People expect random sequences to alternate often. Real random sequences contain longer runs than intuition predicts. In n fair coin flips, the longest run is typically near log2(n), which is about 6 or 7 for 100 flips.
import random
def longest_streak(flips):
best = run = 1
for prev, cur in zip(flips, flips[1:]):
run = run + 1 if cur == prev else 1
best = max(best, run)
return best
rng = random.Random(7)
flips = [rng.choice('HT') for _ in range(100)]
print(longest_streak(flips))Run it with several seeds. The result will usually fall between 5 and 8. A designer who sees a run of six identical results in a playtest log has not found a bug. A sequence that never has a run longer than three would be the suspicious one.
Dry streaks in drop rates
Streaks hurt most in loot and reward systems, where the "bad" outcome is simply nothing happening. Suppose a rare item drops with 5% probability per attempt. The expected wait is 1 divided by 0.05, which is 20 attempts. The probability of getting nothing in n attempts is 0.95 raised to the power n:
| Attempts | Chance of no drop | Meaning |
|---|---|---|
| 14 | about 49% | The median player waits roughly this long. |
| 20 | about 36% | More than a third of players pass the "expected" wait with nothing. |
| 50 | about 7.7% | Roughly 1 in 13 players is still empty-handed. |
| 100 | about 0.6% | Rare, but across a large player base it happens to many people. |
Two points follow from the table. First, the median wait (14) is shorter than the mean wait (20), because a minority of very unlucky players pull the average up. Second, the "bad luck" tail is a fixed percentage of your audience. If 100,000 players try for this item, about 600 of them will go 100 attempts without it. You can confirm the 20-attempt figure by simulation:
import random
rng = random.Random(11)
players = 10000
attempts = 20
dry = 0
for _ in range(players):
if not any(rng.random() < 0.05 for _ in range(attempts)):
dry += 1
print(dry / players) # close to 0.36The printed value will be near 0.358 but not exactly equal to it. That gap is variance in the simulation itself. With 10,000 players the estimate is typically within about one percentage point.
Why short runs feel unfair
Players judge fairness from their own short sample, and several effects make that sample feel worse than it is:
- Loss weighs more than gain. A missed 5% drop is remembered more strongly than the many times nothing was expected.
- Cost accumulates. Each failed attempt costs time or money, so a dry streak feels like a growing debt.
- Players compare with the average. They read "5% chance" as "about once every 20 tries" and treat 40 tries without success as evidence of a broken system.
- Anecdotes spread. The players who got lucky rarely post about it. The unlucky ones do.
The next chapter covers the gambler's fallacy, which is the wrong inference players draw from a streak. Here the point is only that the feeling of unfairness is predictable from the math, not a sign that your random number generator is broken.
Choosing how much variance to allow
Variance is a dial, not a defect. Different mechanics need different settings.
| Design lever | Effect on variance | Typical use |
|---|---|---|
| Many small rolls instead of one large roll | Lowers the spread of the total | Damage over a fight, resource income per turn |
| Smaller outcome range (a d6 instead of a d20) | Lowers spread per roll | Games where skill should dominate |
| Summed dice (2d6 instead of one d12) | Clusters results near the mean | Predictable but not fixed outcomes |
| Shuffle bag | Bounds the length of streaks | Hit or miss sequences, item rotation |
| Pity timer | Caps the dry streak length | Rare drops and gacha-style rewards |
| One high-stakes roll | Raises spread | Tension, comebacks, short party games |
Choose by asking what a single session should feel like. A tournament game wants low variance per decision so skill shows up. A party game wants high variance so a weaker player can win tonight. Match the dial to the promise you make to the player.
Common mistakes
- Judging a mechanic from a few playtests. Ten sessions at 5% variance per roll can show nearly anything. Simulate thousands of runs before deciding that a rate is wrong.
- Reporting only the mean. Always report at least the median and a high percentile, such as the 95th, of the waiting time.
- Fixing streaks by adjusting the odds. Raising the drop rate shortens the average wait but does not remove the tail. Bounding mechanisms such as bags and pity timers act on the tail directly.
- Assuming a fair generator never produces long runs. If your logs show a run of seven, compare it to the expected longest run for the sample size before changing code.
Exercise
A boss drops a rare item with 10% probability per kill. (a) What is the expected number of kills to get it? (b) What is the probability that a player gets no drop in 10 kills? (c) A tester reports "10 kills, nothing, the drop rate is broken." Is that evidence of a bug?
Show answer
(a) The expected number of kills is 1 / 0.10 = 10. (b) The chance of no drop in 10 kills is 0.9^10, which is about 0.349, or roughly 35%. (c) No. About one player in three will reach the expected wait without the item, so a single report of this is normal. To check for a real fault, collect many players' results, or simulate the drop with the same code and compare the distribution of kills needed.
Exercise
You change a damage roll from one d12 to two d6 added together. The mean stays 6.5 per attack. Which version has the lower variance, and what is the effect over a fight of 25 attacks?
Show answer
Two d6 has lower variance. One d12 has variance (12^2 - 1) / 12 = 11.92. Two d6 has variance 2 x 2.917 = 5.83, about half. Over 25 attacks the total damage has the same expected value in both cases (162.5), but the two-d6 version has a standard deviation of about 12.1 against about 17.3 for the d12 (the square root of 25 times each per-attack variance). Fights with two d6 therefore vary less in length and outcome.