rand — Generates a controlled random number series.
iseed (optional, default=0.5) -- a seed value for the recursive pseudo-random formula. A value between 0 and 1 will produce an initial output of kamp * iseed. A value greater than 1 will be seeded from the system clock. A negative value will cause seed re-initialization to be skipped. The default seed value is .5.
isel (optional, default=0) -- if zero, a 16-bit number is generated. If non-zero, a 31-bit random number is generated. Default is 0.
ioffset (optional, default=0) -- a base value added to the random result. New in Csound version 4.03.
kamp, xamp -- range over which random numbers are distributed.
ares, kres -- Random number produced.
The internal pseudo-random formula produces values which are uniformly distributed over the range kamp to -kamp. rand will thus generate uniform white noise with an R.M.S value of kamp / root 2.
The value ares or kres is within is a half-closed interval which contains -xamp, but never contains +xamp.
Here is an example of the rand opcode. It uses the file rand.csd.
Example 865. Example of the rand opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;realtime audio out ;-iadc ;;;uncomment -iadc if RT audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o rand.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 ;same values every time krnd rand 100 printk .5, krnd ; look aout oscili 0.8, 440+krnd, 1 ; & listen outs aout, aout endin instr 2 ;different values every time krnd rand 100, 10 ; seed from system clock printk .5, krnd ; look aout oscili 0.8, 440+krnd, 1 ; & listen outs aout, aout endin </CsInstruments> <CsScore> f 1 0 16384 10 1 ;sine wave. i 1 0 1 i 2 2 1 e </CsScore> </CsoundSynthesizer>
The example will produce the following output:
i 1 time 0.00067: 50.00305 i 1 time 0.50000: 62.71362 i 1 time 1.00000: -89.31885 WARNING: Seeding from current time 472230558 i 2 time 2.00067: -70.65735 i 2 time 2.50000: 69.15283 i 2 time 3.00000: -48.79761