rnd — Returns a random number in a unipolar range at the rate given by the input argument.
rnd(x) (init- or control-rate only)
Where the argument within the parentheses may be an expression. These value converters sample a global random sequence, but do not reference seed. The result can be a term in a further expression.
Here is an example of the rnd opcode. It uses the file rnd.csd.
Example 340. Example of the rnd 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
; Audio out Audio in
-odac -iadc ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o rnd.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
; Instrument #1.
instr 1
; Generate a random number from 0 to 1.
i1 = rnd(1)
print i1
endin
</CsInstruments>
<CsScore>
; Play Instrument #1 for one second.
i 1 0 1
; Play Instrument #1 for one second.
i 1 1 1
e
</CsScore>
</CsoundSynthesizer>
Its output should be:
rnd at i-rate: 0.973500 rnd at k-rate: 0.139405
rnd at i-rate: 0.973500 rnd at k-rate: 0.040065
rnd at i-rate: 0.973500 rnd at k-rate: 0.412845
rnd at i-rate: 0.973500 rnd at k-rate: 0.440650
rnd at i-rate: 0.973500 rnd at k-rate: 0.663581
rnd at i-rate: 0.973500 rnd at k-rate: 0.876723
rnd at i-rate: 0.973500 rnd at k-rate: 0.302459
rnd at i-rate: 0.973500 rnd at k-rate: 0.398580
rnd at i-rate: 0.973500 rnd at k-rate: 0.448875
rnd at i-rate: 0.973500 rnd at k-rate: 0.907728