home/ atoms/ sc-deterministic-seed

SuperCollider's RandSeed and RandID make stochastic synthesis reproducible from a given seed

In SC, UGen-side random generators have per-Synth seed state. RandID.ir(id) assigns a random number generator ID; RandSeed.ir(1, seed) initialises it with a specific seed. Running the same Synth with the same seed produces identical output — crucial for reproducible generative music and debugging. The Figure 2.5 example shows ten different gesture variants from ten different seeds. If seeds are stored, any gesture can be recreated exactly. This is also used for A/B testing and for seeded composition where the score encodes only seeds and an algorithm.

Examples

SynthDef(\UGen_ex5, { |gate=1, seed=0, id=1| RandID.ir(id); RandSeed.ir(1, seed); // … rest of patch is deterministic given same seed }).add; b = Synth(\UGen_ex5, [\seed, 123]); // exact same result each time

Assessment

Run the same stochastic SynthDef twice with seed=42 and record both outputs. Confirm they are identical. Change the seed to 43 and describe how the output differs. Explain why RandID is needed in a multi-Synth context.

“// Using the same seed, we get the same gesture b = Synth(\UGen_ex5, [\seed, 123]);”
corpus · the-supercollider-book-official-code-examples-scbookcode-gpl · chunk 71