Chapter 12

Randomness and Reproducibility

Random numbers, seeds, sampling, shuffling, splitting, saving results, configuration values, and rerunning experiments.

Subject
Python
Lessons
7 lessons
Practice
12 checks
Review
3 pages

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.

  1. 01
    Random Numbers

    NumPy random generators, integers, floats, and random array shapes.

  2. 02
    Seeds

    Initializing generators so random sequences can be repeated.

  3. 03
    Sampling

    Choosing values with replacement, without replacement, and with probabilities.

  4. 04
    Shuffling and Splitting

    Shuffling indices, splitting data, and keeping examples paired with labels.

  5. 05
    Saving Results

    Recording seeds, configuration values, and small summaries for later comparison.

  6. 06
    Configuration Values

    Dataclass configuration records for randomized runs.

  7. 07
    Rerunning an Experiment

    Comparing fixed-seed and unfixed runs, and explaining what can still vary.

  1. Conclusion

    The reproducibility habits that prepare for small numerical experiments.

  2. Review

    A compact review of generators, seeds, sampling, shuffling, saving results, configuration, and reruns.

  3. Exercises

    Chapter-level practice for seeds, sampling, shuffling, and rerunnable simulations.

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

Chapter progress