Probability and simulation
Not met yet
A probability is a number from 0 to 1 that says how often something happens: the share of equally likely outcomes in which it happens, or the share of tries it happens in over a long run. With two dice there are 36 equally likely pairs and six of them total 7, so a 7 has chance 6/36, while a 2 has only one pair and chance 1/36. The chances of all the possible outcomes add up to 1, so the chance something doesn't happen is 1 minus the chance it does; for independent events, the chance both happen is their chances multiplied. When counting is hard, simulate: with rng = np.random.default_rng(seed), rng.random(n) < 0.3 is True about 30 times in a hundred, and the mean of the array is the estimate. A short run wobbles and a long one settles, and no run remembers the last: a coin that has landed tails three times is no more likely to land heads.
Try it
main.pyOutput
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks every total of two dice is equally likely, forgetting to count how many pairs make each one.
- Thinks the chance that two independent things both happen is their chances added, rather than multiplied.
- Thinks a run of one outcome makes the other more likely next time, when independent tries have no memory.
- Thinks a short simulation gives the true chance, rather than a rough estimate that wobbles and only settles over many runs.
- Thinks a seeded random generator gives the same numbers on every call. The seed fixes the sequence; each call takes the next numbers in it.
- Thinks two generators made with the same seed still give different numbers, so a simulation can never be run again exactly.