A d20 with advantage and disadvantage
P75.dice.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: One die, two dice: the distribution of a roll
Where next?
This module unlocks
Go up a level
P75.dice.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: One die, two dice: the distribution of a roll
This module unlocks
Go up a level
Some moments favour a character: Ada knows the river, the sun is behind her, a friend steadies the rope. Some work against her: the fog is thick, her hands are numb. This platform's game says so with the dice, not with a modifier: the player rolls the d20 twice, and keeps the higher roll when the moment is on the character's side, or the lower when it is against her. This lesson works out what that does to the odds, exactly and then by simulation.
The kept roll is then used exactly as in any check: add the modifier, compare with the difficulty. Advantage and disadvantage never stack: two reasons for advantage still mean two dice, and a reason for each cancels out, so the player rolls one die as usual.
Take the simplest case: the die must show 15 or more (a check at +0 against difficulty 15, or Ada's +3 against difficulty 18).
Multiplying the two chances is allowed because the two dice are independent: what one shows tells you nothing about the other. The count agrees: two d20 land in 20 × 20 = 400 ways, and 14 × 14 = 196 of them have both dice below 15, so 400 − 196 = 204 ways succeed with advantage, and 204 ÷ 400 = 51 %.
| The die must show at least | One d20 | Advantage | Disadvantage |
|---|---|---|---|
| 5 | 80 % | 96 % | 64 % |
| 11 | 50 % | 75 % | 25 % |
| 15 | 30 % | 51 % | 9 % |
| 20 | 5 % | 9.75 % | 0.25 % |
The general rule: if one die succeeds with chance p, advantage succeeds with 1 − (1 − p)² and disadvantage with p².
At 11 or more, advantage lifts the chance from 50 % to 75 %: 25 percentage points, the largest gain anywhere on the die. At the ends it adds little: at 20 only from 5 % to 9.75 %, and at 5 from 80 % to 96 %. On average, the higher of two d20 is 13.825 against 10.5 for one die, and the lower is 7.175: advantage is worth a little over three points on average, but up to five points (25 %) in the middle.
Why it matters — A player choosing between a bonus and advantage, or a game master setting a difficulty, needs to know where advantage counts.
The program below computes each chance exactly, by going through all 400 pairs of faces, and by simulation, by rolling the pair ten thousand times with a fixed seed.
import random
from itertools import product
def kept(first, second, mode):
"""The roll a check uses: the higher, the lower, or simply the first."""
if mode == "advantage":
return max(first, second)
if mode == "disadvantage":
return min(first, second)
return first
def at_least_exact(target, mode):
pairs = list(product(range(1, 21), repeat=2))
return sum(1 for a, b in pairs if kept(a, b, mode) >= target) / len(pairs)
def at_least_simulated(target, mode, rolls=10_000, seed=1):
roller = random.Random(seed)
hits = 0
for _roll in range(rolls):
hits += kept(roller.randint(1, 20), roller.randint(1, 20), mode) >= target
return hits / rolls
for target in (5, 11, 15, 20):
for mode in ("normal", "advantage", "disadvantage"):
exact, simulated = at_least_exact(target, mode), at_least_simulated(target, mode)
print(target, mode, exact, simulated, abs(exact - simulated) < 0.01)
# at 15: normal 0.3 0.3027 · advantage 0.51 0.5066 · disadvantage 0.09 0.0892, all True
Every simulated chance in the table lands within one percentage point of the exact one.
What comes next: the average of a roll, and comparing two attacks by their expected damage (Expected value: the average outcome of a choice); and difficulties from easy to hard, and what advantage is worth at each (Difficulty and the odds of success).
The first rung asks for one number, the faces of one d20 that miss 15, and turns it into the chance with advantage, when both dice must miss for the check to fail. The second, written from scratch, computes the chance for any target with or without advantage, by counting every pair, then checks it by simulation.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Loading exercise…
Loading exercise…
Loading your notes...