Ada's first check used one die, a d20, and every face had the same chance: 1 in
20. Role-playing games roll other dice too, and often several at once: two
six-sided dice for a fall, three for a storm. Add two dice together and the
totals stop being equally likely. This lesson counts exactly how likely each
total is, and then checks every count by letting a program roll the dice ten
thousand times.
Dice notation
Games write dice in a short code, dice notationDice notationThe short code games use for a roll: 2d6 + 1 means roll two six-sided dice, add them, then add one.:
nds + m means "roll n dice with s sides each, add them up, then add
m". The d stands for die.
d20: one twenty-sided die, 1 to 20 (the 1 in front is left out).
d6: one ordinary six-sided die, 1 to 6.
2d6: two six-sided dice, added: 2 to 12.
2d6 + 1: the same, plus one: 3 to 13.
1d8 + 3: one eight-sided die plus three: 4 to 11.
One die: every face alike
A fair die lands on each face equally often. A d6 gives each of its six faces
a chance of 1 in 6, about 16.7 %; a d20 gives each face 5 %. Listing every
outcome with its chance is a
probability distributionProbability distributionA list of every outcome something can have, with the chance of each; the chances add up to 1., the
idea “Probability Distributions” (Data Science & AI) develops in general. When every outcome has the
same chance, as with one fair die, the distribution is
uniformUniform distributionA distribution in which every outcome has the same chance, like the faces of one fair die.: drawn as bars, it is flat.
Two dice: a peak in the middle
Roll two d6, one red and one blue, and add them. The red die has six faces and
the blue die has six, so there are 6 × 6 = 36 ways for the pair to land,
all equally likely. Each cell below is one of those ways, with its total:
red ↓ · blue →
1
2
3
4
5
6
1
2
3
4
5
6
7
2
3
4
5
6
7
8
3
4
5
6
7
8
9
4
5
6
7
8
9
10
5
6
7
8
9
10
11
6
7
8
9
10
11
12
Count the cells for each total and divide by 36. That is the distribution of
2d6:
Total
2
3
4
5
6
7
8
9
10
11
12
Ways out of 36
1
2
3
4
5
6
5
4
3
2
1
Chance
2.8 %
5.6 %
8.3 %
11.1 %
13.9 %
16.7 %
13.9 %
11.1 %
8.3 %
5.6 %
2.8 %
The totals are no longer alike. A 7 can be made six ways (1 + 6, 2 + 5, …,
6 + 1), so it comes up 6 times in 36, about 16.7 %. A 2 needs both dice to show
1, and a 12 both to show 6: one way each, about 2.8 %. Drawn as bars, the
distribution rises step by step to 7 and falls away again, a triangle rather
than a flat line.
ⓘ Concept: Why two dice peak in the middle
A middle total can be made many ways: a high red die with a low blue one, a
low red with a high blue, or two middling dice. An extreme total can be made
only one way. So the more dice you add, the more the totals bunch around the
middle, and the rarer the extremes. For example, the chance of 10 or more on
2d6 is 3 + 2 + 1 = 6 ways in 36, about 16.7 %; on one d12 it is 3 faces in
12, 25 %.
Why it matters — A game master who wants most results ordinary and a few extreme rolls two dice instead of one: 2d6 and a d12 have nearly the same range, but very different odds.
Checking by simulation
Counting the 36 ways gives the exact answer. A second, independent check is a
simulationMonte Carlo simulationChecking or estimating a chance by letting a program repeat the random event many times and counting how often each result comes up.: a program rolls the
dice many times and records how often each total comes up. With enough rolls,
each total's share of the rolls comes close to its exact chance. If the two
disagree, one of them has a mistake. The program below does both; its random
seed fixes the dice the program rolls, so that every run prints the
same numbers.
import random
from itertools import product
def two_d6_exact():
"""Every way two d6 can land: total -> exact chance."""
ways = {}
for red, blue in product(range(1, 7), repeat=2):
ways[red + blue] = ways.get(red + blue, 0) + 1
return {total: n / 36 for total, n in sorted(ways.items())}
def two_d6_simulated(rolls=10_000, seed=1):
"""Roll 2d6 many times: total -> share of the rolls."""
roller = random.Random(seed)
seen = {}
for _roll in range(rolls):
total = roller.randint(1, 6) + roller.randint(1, 6)
seen[total] = seen.get(total, 0) + 1
return {total: seen[total] / rolls for total in sorted(seen)}
def d12_simulated(rolls=10_000, seed=1):
"""Roll one d12 many times: face -> share of the rolls."""
roller = random.Random(seed)
seen = {}
for _roll in range(rolls):
face = roller.randint(1, 12)
seen[face] = seen.get(face, 0) + 1
return {face: seen[face] / rolls for face in sorted(seen)}
exact, simulated, d12 = two_d6_exact(), two_d6_simulated(), d12_simulated()
print(round(exact[7], 3), round(simulated[7], 3)) # 0.167 0.168
print(max(abs(exact[t] - simulated[t]) for t in exact) < 0.01) # True
print(round(sum(p for t, p in exact.items() if t >= 10), 3),
round(sum(p for t, p in simulated.items() if t >= 10), 3)) # 0.167 0.162
print(3 / 12, round(sum(p for f, p in d12.items() if f >= 10), 3)) # 0.25 0.247
Over ten thousand rolls, every total's share lands within one percentage point
of its exact chance (a percentage point is the gap between two percentages:
16.7 % and 17.7 % are one point apart). 7 came up 16.8 % of the time, against
an exact 16.7 %; 10 or more on 2d6, and on the d12, land within a point of
16.7 % and 25 % as well. The two methods agree, so both can be trusted.
What this lesson leaves for the next ones: the d20 rolled twice, keeping the
higher or the lower (“A d20 with advantage and disadvantage”), and the average
of a roll, used to compare choices (“Expected value: the average outcome of a
choice”).
Your turn
The first rung asks for one number: how many of the 36 ways make a 7. The
second, written from scratch, builds the whole distribution of 2d6 by counting,
then rolls ten thousand times and compares. Then a short gapped set checks the
words and the numbers.
Ask the mentor about this module
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.
Images, PDF or text. Kept on this device only.
Keeping your files on this device
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.
Ctrl/Cmd + Enter to send
Rung 1 — the ways to make a seven
Loading exercise…
Rung 2 — the distribution of 2d6, counted and rolled
Loading exercise…
Loading the exercise...
My notes on this module
Loading your notes...
One die, two dice: the distribution of a roll — TransformerLab