2 summary:: Random generator seed
3 categories::Core>Kernel, Random
4 related:: Guides/Randomness, Classes/RandSeed, Classes/Pseed, Classes/Thread
8 Every link::Classes/Thread:: in sclang has a (pseudo-) random number generator that is responsible for all randomization within this thread. Each random number generator has its own seed (starting point) from which the series of values is generated. This seed can be set and after that, the randgen (being strictly deterministic) produces exactly the same numbers again.
10 In order to save diskspace, you can reproduce any sequence of randomized data just by one Integer number that you can write down in your notebook.
15 // every thread, also a Routine, has a random generator seed:
18 loop({#[1,2,3,4,5].choose.yield })
23 // using the routine to fill an array
26 // setting the random generator seed back to our initial seed
29 // causes this array to be identical
33 subsection::Inheriting Seeds
35 Also it is possible to set the seed of the running thread that
36 all threads started within will inherit.
39 thisThread.randSeed = 1923;
41 // create a function that returns a routine
44 loop({#[1,2,3,4,5].choose.yield })
47 Array.fill(7, r.value);
50 thisThread.randSeed = 1923;
52 Array.fill(7, r.value);
56 // use the seed to completely reproduce a sound:
58 SynthDef(\help_randomSeed, { arg out=0, freq=440;
60 Line.kr(1, 0, 0.3, doneAction:2) *
62 Dust2.ar([10, 10], 270) + WhiteNoise.ar(4),
67 SynthDef(\help_setRandomSeed, { arg seed=1956, tbus=0.0;
68 RandSeed.kr(tbus, seed);
74 x = Synth(\help_setRandomSeed);
77 Synth(\help_randomSeed, [\freq, rrand(440, 700)]);
90 x.set(\seed, d, \tbus, 1.0); r.randSeed = d;
98 // sound starts to loop
101 d = 1251; // different loop
105 // sound is just like random again, not interested in anything.