Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / HelpSource / Classes / Pmeanrand.schelp
blob1012d4a395e5f6ed709bd16a80b95d4ac4930e38
1 class:: Pmeanrand
2 summary:: random values that tend toward ((lo + hi) / 2)
3 related:: Classes/Plprand, Classes/Phprand
4 categories:: Streams-Patterns-Events>Patterns>Random
6 ClassMethods::
8 method::new
10 argument::lo
11 lower boundary of values.
13 argument::hi
14 upper boundary of values.
16 argument::length
17 number of values produced.
19 Examples::
21 code::
23 var a, c, w;
24 a = Pmeanrand(0.0, 1.0, inf);
25 c = a.asStream.nextN(500);
26 w = Window.new("Pmeanrand", Rect(10, 10, 540, 800));
27 // plot the values
28 c.plot(bounds: Rect(10, 10, 520, 380), discrete: true, parent: w);
29 // a histogram of the values
30 c.histo(500).plot(bounds: Rect(10, 410, 520, 380), parent: w);)
33 // sound example
35 SynthDef(\help_sinegrain,
36         { arg out=0, freq=440, sustain=0.05;
37                 var env;
38                 env = EnvGen.kr(Env.perc(0.01, sustain, 0.2), doneAction:2);
39                 Out.ar(out, SinOsc.ar(freq, 0, env))
40         }).add;
44 var a;
45 a = Pmeanrand(0.0, 1.0, inf).asStream;
47         loop {
48                 Synth(\help_sinegrain, [\freq, a.next * 600 + 300]);
49                 0.02.wait;
50         }
51 }.fork;
54 // this is equivalent to:
57         loop {
58                 Synth(\help_sinegrain, [\freq, (rrand(0.0, 1.0) + rrand(0.0, 1.0) * 0.5) * 600 + 300]);
59                 0.02.wait;
60         }
61 }.fork;