skip to content

A random-drawing step records its seed beside the result — what does the recorded seed fix, and what does it not?

level: middleimportance: should knowfreq 45%

answer

  1. one generator, one stream
  2. the seed fixes draws, not runs
  3. parallel workers each have their own
  4. distance between seeding and drawing
  5. arbitrary iteration order is not a draw

basics

~20 s

A recorded seed fixes the sequence of draws taken from the generator that was seeded, in the order they are taken. It reaches no other generator, no parallel worker drawing from its own stream, and nothing whose result depends on an arbitrary iteration order.

solid answer

~50 s

Seeding means fixing the starting point of a random generator and writing that starting point down beside the result, as part of the evidence the file reproduces. What it buys is precise: the same generator, seeded the same way, hands out the same values in the same order. What it does not buy is a reproducible run. Other components frequently hold generators of their own and never consult the one you seeded. Work split across parallel workers gives each worker its own stream, and the interleaving varies. Anything whose result depends on iteration order over a hash-based structure, or on the order concurrent results arrive, moves regardless of any seed. And in an interactive session — a long-lived process that keeps every value blocks ever bound — a seed set in one block and drawn on in another depends on how many draws happened in between.

go deeper

for a junior

Recall what a seed is: the starting point of a random generator, fixed on purpose and written down beside the result so the same values can be produced again.

for a middle

Explain the boundary of the guarantee — the generator you seeded, in draw order — and name what sits outside it: other generators, parallel streams, and results that depend on an arbitrary iteration order.

for a senior

Diagnose a run that stopped reproducing: locate every generator in play, check whether anything was split across workers, and confirm the draws still happen the same number of steps after the seeding.

for a principal

Decide what a result's evidence must state before it is acted on — seed, parallelism, input identity, and the tolerance a re-run is allowed — and who is accountable for producing it.

## What a seed is, and the one thing it fixes A random generator produces a long deterministic sequence of values from a starting point. **A recorded seed** is that starting point, fixed deliberately and written down beside the result, so the same sequence can be produced again. It belongs in the same evidence as **a clean run from empty** — a new process with nothing bound, executing every block once in the order the file lists them — because a file with an unrecorded random step does not reproduce even when everything else about it does. The guarantee is narrow and exact: **the same generator, seeded with the same value, hands out the same numbers in the same order.** Every extension of that sentence past 'the generator you seeded' is an assumption, and this is the question interviewers use to find out whether a candidate has ever checked one. ## The distance between the block that seeds and the block that draws This is the version specific to an interactive session, and it catches people who know the rest. Set the starting point in one **block**, draw in another, and the values you get depend on **how many draws happened in between** — because the generator advances with every value it hands out and nothing rewinds it at a block boundary. So the same file gives different numbers depending on how the session was driven: - You re-executed the drawing block to look at the output again; the second execution continues from where the first left off. - You ran an exploratory block that drew a few values and then deleted it; the generator advanced anyway. - You inserted a new step above the drawing block; every draw below it now starts from a different position. None of these change the file in a way that explains the moving number, which is why the symptom is reported as 'the seed does not work'. It works; the draws are not where you think they are. The habit that fixes it is to seed immediately before the work that draws, in the same block, so the distance between the two is zero — and then to prove the whole thing with a clean run from empty, where the draw count is whatever the file says it is. ## What a seed does not reach | Source of variation | Does one recorded seed fix it? | Why | |---|---|---| | Serial draws from the generator you seeded | Yes | This is exactly the guarantee | | A component holding its own generator | No | It never consults the one you seeded | | Parallel workers, one stream each | No | Each stream advances independently and the interleaving varies | | Iteration over a hash-based structure | No | The order is arbitrary and is not a draw | | The order concurrent results arrive | No | Timing, not randomness | | A different generator implementation | No | The same seed on a different algorithm gives different values | | Input data that moved | No | The seed governs the generator, never the input | The parallel row is worth dwelling on. Splitting work across workers is the single most common way a run that reproduced yesterday stops reproducing today, and nothing about it looks random from the outside: the code is identical, the seed is identical, and the answer moves by a fraction of a percent every run. ## Recording it so it counts as evidence 1. **Choose the value explicitly** and write it into the file, rather than letting the tool pick one and never learning what it picked. 2. **Seed each generator that is actually in play,** or pass one generator explicitly into the components that need one, so there is a single stream rather than several you have not enumerated. 3. **Print the seed with the result,** not only in the file. A number quoted in writing without its seed cannot be checked later by anybody. 4. **Say whether anything ran in parallel,** because that one sentence tells a reader whether to expect an exact match or a close one. 5. **State the tolerance** you would accept on a re-run when an exact match is not available, so 'it did not reproduce' becomes a measurement rather than an argument. ## The honest sentence Rather than 'the seed makes it reproducible', write what you actually checked: *'seed recorded; one generator, seeded in the same block as the draws; single-threaded; clean run from empty gives the identical figure.'* Every clause there is something a reader can falsify, and each one names a source of variation the seed alone does not cover. A seed is one line of the evidence, not the whole of it.

  • The same file, same seed, single-threaded, gives a slightly different answer on a colleague's machine. What is left?
    The generator implementation and the input. The same starting point on a different algorithm produces a different sequence, so a version difference in whatever supplies the draws is enough. So is an input read as 'the latest' rather than pinned to a stated snapshot. Check the input identity first, since it is cheaper to establish, then compare the versions the two runs actually used.
  • Why is 'the tool picked a seed for me and the run reproduced' not good enough?
    Because the value was never written down. The run reproduced within one session because the generator happened to be in the same place, and there is nothing to quote to anyone reconstructing the result next month. Choose the value explicitly and record it beside the number. A seed that only the process knows disappears with the process, exactly like every other binding.

saying these in an interview costs you the question

  • Setting the seed once makes the whole run reproducible.
  • Parallel workers all draw from the generator you seeded.
  • The seed also fixes which records the step reads.
  • The same seed gives the same values under any implementation.
  • The generator restarts at the seed when a block finishes.