Sub topic 4
Expected value: the average outcome
What this chapter assumes
You should be comfortable with fractions and percentages, and with common game mechanics such as dice, cards, and loot. You should also be able to read short Python programs. The previous chapter covered basic probability: the probability of an outcome is a number from 0 to 1, and the probabilities of all possible outcomes add up to 1. This chapter builds on that.
What expected value means
The expected value (EV) of a random outcome is the average result you would get if you repeated it a very large number of times. To compute it, multiply each possible value by its probability, then add the products.
For a fair six-sided die, each face has probability 1/6, so:
EV = 1×(1/6) + 2×(1/6) + 3×(1/6) + 4×(1/6) + 5×(1/6) + 6×(1/6) = 21/6 = 3.5
Because every face is equally likely, you can also just average the faces:
faces = [1, 2, 3, 4, 5, 6]
expected_value = sum(faces) / len(faces)
print(expected_value) # 3.5The EV of 3.5 is not a result you can roll. EV describes the long-run average, not a typical single outcome.
Weighted outcomes
Most game mechanics do not have equally likely outcomes, so you need the full formula with a probability for each value. Suppose an attack has three results:
| Result | Damage | Probability |
|---|---|---|
| Miss | 0 | 0.20 |
| Hit | 10 | 0.70 |
| Critical hit | 25 | 0.10 |
The EV is 0×0.20 + 10×0.70 + 25×0.10 = 0 + 7 + 2.5 = 9.5 damage per attack. This function works for any list of (value, probability) pairs:
def expected_value(outcomes):
"""outcomes: list of (value, probability) pairs."""
total_p = sum(p for _, p in outcomes)
if abs(total_p - 1) > 1e-9:
raise ValueError(f"probabilities sum to {total_p}, expected 1")
return sum(value * p for value, p in outcomes)
attack = [(0, 0.20), (10, 0.70), (25, 0.10)]
print(round(expected_value(attack), 2)) # 9.5The check on the probabilities catches a common data-entry mistake. If the weights in your table sum to 0.9 or 1.1, the EV is silently wrong.
Check EV against a simulation
A simulation repeats the mechanic many times and averages the results. It should land near the formula's answer:
import random
rng = random.Random(5)
values = [0, 10, 25]
weights = [0.20, 0.70, 0.10]
samples = rng.choices(values, weights=weights, k=100000)
print(sum(samples) / len(samples)) # close to 9.5, not exactly 9.5The simulated average will be near 9.5 but almost never exactly 9.5. The more samples you draw, the closer it gets. A later chapter on simulation testing builds on this idea.
Adding up several random events
EV is easy to combine because of linearity of expectation: the EV of a sum is the sum of the EVs. This holds even when the events depend on each other. Two dice therefore have an EV of 3.5 + 3.5 = 7. You can confirm this by listing all 36 equally likely pairs:
from itertools import product
pairs = list(product(range(1, 7), repeat=2))
print(sum(a + b for a, b in pairs) / len(pairs)) # 7.0Linearity also lets you scale and shift. A weapon that rolls one die and adds 2 damage has an EV of 3.5 + 2 = 5.5. A spell that rolls three dice has an EV of 3 × 3.5 = 10.5. You rarely need to enumerate outcomes when you can add the parts.
Linearity applies to sums. It does not apply to products or to "best of" rules. Rolling two dice and keeping the higher one does not have an EV of 3.5, and you must enumerate that case. Rolling with advantage in tabletop games works this way, and its EV is about 4.47.
Expected number of attempts
A different question comes up often in loot design: how many tries until the first success? If each attempt succeeds independently with probability p, the expected number of attempts is 1/p.
- A 1-in-6 chance takes 6 attempts on average.
- A 2% drop chance takes 1/0.02 = 50 attempts on average.
This average hides a wide spread. With a 2% chance, about 36% of players still have no drop after 50 attempts, because 0.98^50 ≈ 0.36. The average is 50, but many individual players wait far longer. This gap between the mean and the experience of a single player is the subject of the next chapters on variance and pity systems.
Using EV to make design decisions
EV turns a vague question ("is this reward good?") into a number you can compare. Common uses:
- Pricing. If a pack pays out 9 gold on average and costs 9 gold, it is break-even. Charging less gives players a profit on average, and charging more is a loss on average.
- Matching options. If two abilities should be equally strong, equalize their EVs, then adjust the other properties (reliability, cost, flavor) deliberately.
- Finding broken choices. If one option's EV is far above the rest, players will converge on it.
- Tuning an economy. Total currency entering the game per hour is the EV of each source multiplied by how often players use it.
Two options can share an EV and still feel very different. A guaranteed 5 gold and a 50% chance of 10 gold both have an EV of 5. The first has no risk and the second has a lot. Choosing between them is a risk and reward decision, covered in a later chapter. EV tells you the average, and it says nothing about the spread.
Common errors
- Treating EV as a prediction. A player who opens one pack with an EV of 9 gold may get 0 or 50. Use EV to judge the mechanic, not to promise a result.
- Ignoring non-monetary value. EV works on numbers. If outcomes are "a rare card" or "a lost turn," you must first assign them values, and that assignment is a design judgment you should state openly.
- Probabilities that do not sum to 1. Validate every table, as the function above does.
- Mixing up percent and fraction. A 5% chance is 0.05. Using 5 gives an EV 100 times too large.
- Averaging outcomes without weights. Averaging 0, 10, and 25 gives 11.67, not 9.5. The unweighted average is only correct when the outcomes are equally likely.
- Applying linearity to non-sums. "Take the best of two rolls" and "roll again on a 1" need their own calculation.
Exercise
Exercise
A card pack gives 0 gold with probability 0.50, 10 gold with probability 0.40, and 50 gold with probability 0.10. (a) What is the expected value of one pack? (b) The pack costs 12 gold. What is the expected net result per pack, and what does it mean for the player's gold over many packs?
Show answer
(a) EV = 0×0.50 + 10×0.40 + 50×0.10 = 0 + 4 + 5 = 9 gold. (b) The expected net result is 9 − 12 = −3 gold per pack. Over many packs the player loses 3 gold per pack on average, so the pack is a gold sink. Any single pack can still produce a profit, for example the 50-gold result nets +38.