// nice example by dan sheldon showing how to use a random number generator and a fader // remember that rand outputs a value between its argument and zero, at the resolution // (real or int) of its argument.... (lp) ( var w, a, b, button, output; w = GUIWindow.new("rand test", Rect.newBy( 582, 251, 295, 119 )); StringView.new( w, Rect.newBy( 21, 13, 42, 22 ), "range"); a = NumericalView.new( w, Rect.newBy( 69, 15, 64, 20 ), "NumericalView", 0, 1, 10, 1, 'linear'); b = SliderView.new( w, Rect.newBy( 143, 15, 128, 20 ), "SliderView", 0, 1, 10, 1, 'linear'); button = ButtonView.new( w, Rect.newBy( 76, 46, 150, 22 ), "generate random number", 0, 0, 1, 0, 'linear'); StringView.new( w, Rect.newBy( 79, 81, 46, 22 ), "output"); output = NumericalView.new( w, Rect.newBy( 132, 81, 64, 20 ), "NumericalView", 0, -1e+10, 1e+10, 0, 'linear'); a.action = {b.value = a.value;}; b.action = {a.value = b.value;}; button.action = {output.value = rand(a.value) ;}; ) // use rand and spawn to generate a randomized melody, calling random values in real time // lp, ds ( var w, a, b, s, env, output, randFunc, dur; w = GUIWindow.new("rand test", Rect.newBy( 582, 251, 295, 119 )); StringView.new( w, Rect.newBy( 21, 13, 42, 22 ), "range"); a = NumericalView.new( w, Rect.newBy( 69, 15, 64, 20 ), "NumericalView", 0, 1, 10, 1, 'linear'); b = SliderView.new( w, Rect.newBy( 143, 15, 128, 20 ), "SliderView", 0, 1, 10, 1, 'linear'); StringView.new( w, Rect.newBy( 79, 81, 46, 22 ), "output"); output = NumericalView.new( w, Rect.newBy( 132, 81, 64, 20 ), "NumericalView", 0, -1e+10, 1e+10, 0, 'linear'); a.action = {b.value = a.value}; b.action = {a.value = b.value}; { dur = 0.1; env = Env.linen(0.05* dur, 0.6 * dur, 0.3 * dur); t = Spawn.ar({SinOsc.ar((200 * rand(a.value)), 0, EnvGen.kr(env))}, 1, dur + rand(a.value) , 10000); t }.play; ) // plot a random signal, modulated by a sine wave.... this shows how to use random signals, not numbers (functions) // lp, ds ( { s = SinOsc.ar(1000); t = abs(WhiteNoise.ar(s)); [abs(s),t] }.plot )