Sub topic 1
Why games use randomness
This chapter sets up the core ideas for the rest of the tutorial: why designers add chance, how to describe probability, and why sums of dice cluster around the middle.
Prerequisites
This chapter assumes you know basic arithmetic with fractions and percentages, you have seen dice, cards, and loot drops in games, and you can read simple Python. Familiarity with sum(), len(), and list comprehensions is enough.
Why games use randomness
Randomness gives players outcomes they cannot fully predict. It creates variety, replay value, and moments of surprise. A game with no chance can still be deep, but it often feels the same each time.
Input randomness vs output randomness
Input randomness changes the starting conditions, such as a shuffled deck or a random map. Output randomness changes the result of an action, such as a die roll that decides whether an attack hits. Input randomness suits setup and variety. Output randomness suits moments that need tension, but it can frustrate players when it decides outcomes they expected to control.
Probability basics for designers
A probability is a number from 0 to 1 that describes how likely an event is. For a fair six-sided die, the chance of any one face is 1/6, or about 16.7%. For two independent events, multiply their probabilities.
Expected value: the average outcome
The expected value is the average result over many trials. For a fair die it is the sum of the faces divided by the number of faces.
faces = [1, 2, 3, 4, 5, 6]
expected_value = sum(faces) / len(faces)
print(expected_value) # 3.5Expected value tells you the long-run average, not what happens on any single roll.
Distributions: why summed dice cluster
A distribution lists how often each result occurs. One die gives a flat distribution. Summing two dice produces a peak at 7, because more pairs of faces add to 7 than to any other total.
from collections import Counter
from itertools import product
faces = range(1, 7)
sums = Counter(a + b for a, b in product(faces, repeat=2))
print(sums[7] / 36) # 0.1666...
print(sums[2] / 36) # 0.0277...Exercise
What is the probability of rolling a sum of 2 with two fair six-sided dice?
Show answer
Only the pair (1, 1) gives 2, so the probability is 1/36, about 2.8%.