Chapter 12
Randomness and Reproducibility
Random numbers, seeds, sampling, shuffling, splitting, saving results, configuration values, and rerunning experiments.
What this chapter does
Randomness is useful for simulations, sampling, and experiments, but it must be controlled enough to debug and compare. This chapter teaches the seed and configuration habits that make small randomized work rerunnable.
Lessons
Read these in order.
The chapter opening gives the main idea. Move through these lessons next; each page reuses ideas from the pages before it.
- 01Random Numbers
NumPy random generators, integers, floats, and random array shapes.
- 02Seeds
Initializing generators so random sequences can be repeated.
- 03Sampling
Choosing values with replacement, without replacement, and with probabilities.
- 04Shuffling and Splitting
Shuffling indices, splitting data, and keeping examples paired with labels.
- 05Saving Results
Recording seeds, configuration values, and small summaries for later comparison.
- 06Configuration Values
Dataclass configuration records for randomized runs.
- 07Rerunning an Experiment
Comparing fixed-seed and unfixed runs, and explaining what can still vary.
You are ready when
- Generate random integers and floats.
- Use seeds to make random sequences repeatable.
- Sample with and without replacement.
- Shuffle and split paired data safely.
- Save seed, configuration, and result summaries.
- Rerun a small randomized experiment and compare outputs.
Where this leads
- Small Numerical Experiments