As in any computer program, there are no "truly random" number generators in SC. They are pseudo-random, meaning they use very complex, but deterministic algorithms to generate sequences of numbers that are long enough and complicated enough to seem "random" for human beings. (i.e. the patterns are too complex for us to detect.)
If you start a random number generator algorithm with the same "seed" number several times, you get the same sequence of random numbers. (See example below, randomSeed)
You can seed a random generator in order to repeat the same sequence of random numbers:
See also Random Seed.
Demonstrate the various statistical distributions visually, with histograms:
Use a histogram to display how often each (integer) occurs in a collection of random numbers, :
A histogram for linrand:
A histogram for bilinrand:
A histogram for exprand:
And for sum3rand (cheap quasi-gaussian):
All of the single-number methods also work for (Sequenceable)Collections, simply by applying the given random message to each element of the collection:
An integral table can be used to create an arbitrary random distribution quite efficiently. The table building is expensive though. The more points there are in the random table, the more accurate the distribution.
coin simulates a coin toss and results in true or false. 1.0 is always true, 0.0 is always false, 0.5 is 50:50 chance.
biased random decision can be simulated bygenerating a single value and check against a threshhold:
choose : equal chance for each element.
wchoose(weights) : An array of weights sets the chance for each element.
The probability argument sets the chance that two adjacent elements will be separated.
Also see UGens>Generators>Stochastic in the Browse: UGens>Generators>Stochastic page.
Unary or binary random method produce a random value for each frame (not implemented in some cases). This can be used to implement tendency masks.
Like using randSeed to set the random generatorsfor each thread in sclang, you can choose which of several random generators on the server to use, and you can reset (seed) these random generators:
see random patterns with analogous names
Pwalk( (0 .. 10), Prand([ -2,-1, 1, 2], inf));random walk.
some basic examples