Monte Carlo & Randomized Methods

a random seed

Think of a pseudorandom generator as an enormously long, fixed book of 'random' digits printed once and stored inside the algorithm. The seed is the page number you open to. Give the same page number and you read the same passage every time; give a different page number and you start somewhere else in the same book. A random seed is simply the initial state you hand the generator to decide WHERE in its deterministic stream the numbers begin.

Mechanically, the generator's whole output is a function of its starting state, and the seed sets that state. Seed it with the value 42 and you get one fixed sequence; seed it with 43 and you get a completely different-looking one. This gives you two opposite powers. To make a run REPRODUCIBLE — so you, a collaborator, or a reviewer can rerun the exact same simulation and get the identical numbers — you fix the seed explicitly. To get a fresh, unpredictable run each time, you draw the seed from an outside source of genuine entropy (the operating system's hardware randomness, the clock, mouse jitter) and never reuse it.

Seeding is where reproducibility and independence quietly go wrong. Reusing the same seed when you meant independent experiments makes all your 'repeats' identical, faking certainty. Seeding parallel workers with the clock can hand several of them the SAME seed (the clock barely changes in microseconds), correlating runs you believed were independent. And to be truly reproducible you must pin not just the seed but the exact generator and library version, since different generators turn the same seed into different streams. The discipline is simple: log the seed with every result, and for parallel work use a generator built to spawn independent substreams from one master seed.

Set the seed to 7, run a Monte Carlo estimate of pi, and you get, say, 3.1428. Close the program, set the seed to 7 again, rerun — you get exactly 3.1428, every bit identical. Change the seed to 8 and the estimate becomes 3.1392: same method, different random draws.

Same seed, same stream — the key to reproducible randomness.

Fixing a seed makes results reproducible but can give a falsely rosy picture: a method that happens to work on seed 42 may fail on others. Always test across several independent seeds, and report the seed so others can reproduce you.

Also called
seed valueRNG seed種子值亂數種子