ir rnd31 iscl, irpow[, iseed] kr rnd31 kscl, krpow[, iseed] ar rnd31 kscl, krpow[, iseed]
31-bit bipolar random generators with controllable distribution. These units are portable, in that using the same seed value will generate the same random sequence on all systems. The distribution of generated random numbers can be varied at k-rate.
irpow – controls the random distribution of grain frequency. If irpow is positive, the distribution (where x is in the range -1 to 1) is:
For negative irpow values, the distribution is:
(1 - abs(x))(-1/irpow)-1
Setting irpow to -1, 0, or 1 will result in uniform distribution. This is also faster to calculate.
iseed – seed value for the random number generator. iseed must be a positive integer in the range 1 to 2147483646 (231 - 2)). iseed is global for i-rate output, but local for k- and a-rate output. If iseed <= 0, the current time is used as the seed (Default).
iscl – output scale. The random numbers are generated in the range -iscl to iscl.
krpow – same as irpow, except can be varied at k-rate
kscl – same as iscl, except can be varied at k-rate
Although seed values up to 2147483646 are allowed, smaller values (<105) are recommended for portability. Larger integers may be rounded to different values if 32-bit floats are used.
Seeding from the current time will generate a different random sequence with each call, even if there are multiple calls of rnd31 in a very short period. In the a- and k-rate versions, the seed is set at opcode initialization. With i-rate output, if iseed <= 0, it will seed from the current time in the first call, and return the next value from the random sequence in successive calls.
Positive seed values are set at all i-rate calls. i-rate rnd31 with a positive seed will always produce the same output value. This is intentional. To get different values, use iseed = 0 in successive calls, which will return the next value from the random sequence.
The following example produces a-rate random numbers in the range -2 to 2 with triangle distribution, seeded from the current time.
a1 rnd31 2, -0.5
The following example produces k-rate random numbers in the range -1 to 1 with uniform distribution and a seed value of 10.
k1 rnd31 1, 0, 10
The following example produces i-rate random numbers with linear distribution and a seed value of 7. Note that iseed = 7 was used only in the first call.
i1 rnd31 1, 0.5, 7 i2 rnd31 1, 0.5 i3 rnd31 1, 0.5
The same as above but seeding from the current time.
i1 rnd31 1, 0.5, 0 i2 rnd31 1, 0.5 i3 rnd31 1, 0.5
New in Csound 4.16