home/ atoms/ sc-language-ugen-random

Language-side random functions in a SynthDef choose values at compile time, not at Synth creation

SuperCollider has both language-side random functions (lowercase: exprand, rrand, rand) and UGen random generators (uppercase: ExpRand, IRand, Rand). When lowercase functions appear inside a SynthDef, their values are chosen when the SynthDef is compiled (i.e., when .add is called), and every subsequent Synth instance gets the same value. This is usually wrong for per-instance variation. Uppercase UGen versions choose new values each time a Synth is instantiated. To get N unique UGen random values inside a SynthDef, wrap the UGen in curly braces and use !N: {ExpRand(50,1200)}!8.

Examples

{exprand(50,1200)}!8 — picks one language value at compile time, duplicated 8 times (wrong). {ExpRand(50,1200)}!8 — creates 8 UGens each choosing a new random value per Synth (correct).

Assessment

A student’s SynthDef generates 8 sine waves with {exprand(50,1200)}!8 for frequencies. All instances of the Synth sound identical. Diagnose the bug and fix it using one character change.

“Using lowercase exprand in a SynthDef chooses random values when the SynthDef is compiled, and these random values remain fixed, for every instance of Synth that's created.”
corpus · supercollider-tutorials-full-transcripts-and-code-eli-fields · chunk 12