What does seeding with np.random.seed() or default_rng(seed) do, and why does it matter for reproducibility?

Quick Overview

Asks what seeding a NumPy random generator does, comparing the legacy global np.random.seed() with an independent Generator from default_rng. Tests understanding of pseudo-random state, reproducible experiments and the common ways seeding fails to make results repeatable.

What does seeding with np.random.seed() or default_rng(seed) do, and why does it matter for reproducibility?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the purpose of `np.random.seed()` or the modern `default_rng` with a seed, and why is it important for reproducibility? ```hint Where the state lives Compare where each API keeps the generator's state, and think about what else in a program can read from or advance that state. ``` ### What a Strong Answer Covers - That NumPy's random numbers come from a deterministic algorithm and the seed sets its starting state. - The difference between the single global state behind `np.random.seed()` and the independent `Generator` returned by `default_rng`. - Concrete reasons reproducibility matters, such as rerunning experiments, deterministic debugging, stable tests, and consistent splits and initializations. - The limits of seeding: other libraries' generators, parallel workers and version changes. ### Follow-up Questions - How would you give four parallel worker processes random streams that are independent of each other but still reproducible? - You call `np.random.seed(0)` at the top of a training script, yet two runs give different results. Where would you look? - Why is reporting a model's accuracy from a single seed a weak result, and what would you report instead?

Overview: Asks what seeding a NumPy random generator does, comparing the legacy global np.random.seed() with an independent Generator from default_rng. Tests understanding of pseudo-random state, reproducible experiments and the common ways seeding fails to make results repeatable.

Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the purpose of np.random.seed() or the modern default_rng with a seed, and why is it important for reproducibility?

What a Strong Answer Covers Guidance

  • That NumPy's random numbers come from a deterministic algorithm and the seed sets its starting state.
  • The difference between the single global state behind np.random.seed() and the independent Generator returned by default_rng .
  • Concrete reasons reproducibility matters, such as rerunning experiments, deterministic debugging, stable tests, and consistent splits and initializations.
  • The limits of seeding: other libraries' generators, parallel workers and version changes.

Follow-up Questions Guidance

  • How would you give four parallel worker processes random streams that are independent of each other but still reproducible?
  • You call np.random.seed(0) at the top of a training script, yet two runs give different results. Where would you look?
  • Why is reporting a model's accuracy from a single seed a weak result, and what would you report instead?