Outcomes and events
Probability measures how likely something is. Start with an experiment: roll two fair dice. One result, like die 1 showing 3 and die 2 showing 4, is called an outcome. Write it as the pair (3, 4).
The sample space is the set of every possible outcome. Die 1 has 6 faces and die 2 has 6 faces, so there are 6 × 6 = 36 pairs. Each square on the board is one outcome.
An event is a set of outcomes we care about. Let A be "the sum is 7". Six squares belong to A: (1, 6), (2, 5), (3, 4), (4, 3), (5, 2) and (6, 1). They lie on one diagonal.
Counting chance
When every outcome is equally likely, as with fair dice, P(A) = (outcomes in A) ÷ (all outcomes). For a sum of 7 that is 6/36 = 1/6, about 0.167. Expect a 7 about once in every six rolls.
A probability is always between 0 and 1. A sum of 13 is impossible: no square has it, so P = 0/36 = 0. A sum from 2 to 12 is certain: all 36 squares, so P = 36/36 = 1.
Combining events
"Not A" holds every outcome outside A. Since some outcome always happens, P(not A) = 1 − P(A). The sum is not 7 in 30 squares: 30/36 = 5/6, the same as 1 − 1/6.
Let B be "at least one die shows 6". Die 1 is 6 in the bottom row, 6 squares. Die 2 is 6 in the last column, 6 squares. (6, 6) is in both, so B has 6 + 6 − 1 = 11: 11/36.
For "A or B", add both events, then subtract the overlap: P(A or B) = P(A) + P(B) − P(A and B). (1, 6) and (6, 1) are in both: 6 + 11 − 2 = 15, so 15/36 = 5/12.
The two dice do not affect each other: they are independent. Then P(both happen) = P(first) × P(second). "Die 1 is 6" covers one row, 1/6. "Die 2 is 6" covers one column, 1/6. Both: one square, 1/6 × 1/6 = 1/36.
In code
A probability also predicts the long run. Python's randint(1, 6) rolls a die. In 4 rolls we got two 7s, far from 1/6. In 60,000 rolls we got 9,978 sevens: 0.166, very close to 1/6. More rolls, closer match.
Try it in the Python prompt
;; step 1/10 · Roll two dice >>> from fractions import Fraction >>> from random import randint, seed >>> D = range(1, 7) # a die: 1 to 6 >>> (3, 4) == (4, 3) # order matters: die 1 first False
The Python lines in the steps build on each other: run them in order in one session, starting with the imports in step 1. Fraction keeps answers exact: Fraction(6, 36) prints as Fraction(1, 6). Floats round, so float(Fraction(1, 6)) prints 0.16666666666666666.