urandom
Prev | Orchestra Opcodes and Operators | Next

## urandom

urandom — truly random opcodes with controllable range.

## Description

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

## Syntax

    ax urandom [imin, imax]

    ix urandom [imin, imax]

    kx urandom [imin, imax]

## Initialization

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.

## Performance

ax -- a-rate output value.

kx -- k-rate output value.

## Examples

Here is an example of the urandom opcode at a-rate. It uses the file urandom.csd.

Example 1093. 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           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o rnd31.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
      ; Create random numbers at a-rate in the range -2 to 2
      aur urandom  -2, 2

      ; Use the random numbers to choose a frequency.
      afreq = aur * 500 + 100

      a1 oscil 30000, afreq, 1
      out a1
    endin

    </CsInstruments>
    <CsScore>

    ; Table #1, a sine wave.
    f 1 0 16384 10 1

    ; Play Instrument #1 for one second.
    i 1 0 1
    e

    </CsScore>
    </CsoundSynthesizer>

Here is an example of the urandom opcode at k-rate. It uses the file urandom_krate.csd.

Example 1094. An example of the urandom opcode at k-rate.

    <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 rnd31_krate.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
      ; Create random numbers at k-rate in the range -1 to 1
      ; with a uniform distribution.
      k1 urandom

      printks "k1=%f\\n", 0.1, k1
    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument #1 for one second.
    i 1 0 1
    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

## Credits

Author: John ffitch

New in version 5.13

Prev | Up | Next
upsamp | Home | urd