urandom — truly random opcodes with controllable range.
Plugin opcode in urandom.
Truly random opcodes with controllable range. These units are for Unix-like systems only and use /dev/urandom to construct Csound random values
ix -- i-rate output value.
imin -- minimum value of range; defaults to -1.
imax -- maximum value of range; defaults to +1.
Notes | |
---|---|
The algorithm produces 2^64 different possible values which are scaled to fit the range requested. The randomness comes form the usual Linux/OSX /dev/urandom method, and there is no guarantee that it will be truly random, but there is a good chance. It does not show any cycles. |
Here is an example of the urandom opcode at a-rate. It uses the file urandom.csd.
Example 1130. An example of the urandom opcode at a-rate.
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 ;;;RT audio out ; For Non-realtime ouput leave only the line below: ; -o urandom.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 ; Create random numbers at a-rate in the range -2 to 2 aur urandom -2, 2 afreq1 = aur * 500 + 100 ; Use the random numbers to choose a frequency. afreq2 = aur * 500 + 200 a1 oscil .3, afreq1 a2 oscil .3, afreq2 outs a1, a2 endin </CsInstruments> <CsScore> i 1 0 3 e </CsScore> </CsoundSynthesizer>
Here is an example of the urandom opcode at k-rate. It uses the file urandom_krate.csd.
Example 1131. An example of the urandom opcode at k-rate.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in -odac ;;;RT audio out ; For Non-realtime ouput leave only the line below: ; -o urandom_krate.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 ; Create random numbers at k-rate in the range -1 to 1 at krate k1 urandom ; with a uniform distribution. printks "k1=%f\\n", 0.1, k1 asig1 poscil.2, k1 * 500 + 100 asig2 poscil.2, k1 * 500 + 200 outs asig1, asig2 endin </CsInstruments> <CsScore> i 1 0 3 e </CsScore> </CsoundSynthesizer>
Its output should include lines like this:
k1=0.229850 k1=-0.077047 k1=-0.199339 k1=-0.620577 k1=-0.119447 k1=-0.596258 k1=0.525800 k1=-0.171583 k1=-0.017196 k1=-0.974613 k1=-0.036276