urd
Prev | Orchestra Opcodes and Operators | Next

## urd

urd — A discrete user-defined-distribution random generator that can be used as a function.

## Description

A discrete user-defined-distribution random generator that can be used as a function.

## Syntax

    aout = urd(ktableNum)

    iout = urd(itableNum)

    kout = urd(ktableNum)

## Initialization

itableNum -- number of table containing the random-distribution function. Such table is generated by the user. See GEN40, GEN41, and GEN42. The table length does not need to be a power of 2

## Performance

ktableNum -- number of table containing the random-distribution function. Such table is generated by the user. See GEN40, GEN41, and GEN42. The table length does not need to be a power of 2

urd is the same opcode as duserrnd, but can be used in function fashion.

For a tutorial about random distribution histograms and functions see:

- D. Lorrain. "A panoply of stochastic cannons". In C. Roads, ed. 1989. Music machine. Cambridge, Massachusetts: MIT press, pp. 351 - 379.

## Examples

Here is an example of the urd opcode. It uses the file urd.csd.

Example 1064. Example of the urd 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 realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o urd.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1

    ktab  = 1			;ftable 1
    kurd  = urd(ktab)
    ktrig metro 5			;triggers 5 times per second
    kres  samphold kurd, ktrig	;sample and hold value of kurd
          printk2 kres		;print it
    asig  poscil .5, 220+kres, 2
          outs asig, asig
    endin

    instr 2

    seed 0	;every run new values

    ktab  = 1 			;ftable 1
    kurd  = urd(ktab)
    ktrig metro 5			;triggers 5 times per second
    kres  samphold kurd, ktrig	;sample and hold value of kurd
          printk2 kres		;print it
    asig  poscil .5, 220+kres, 2
          outs asig, asig

    endin
    </CsInstruments>
    <CsScore>
    f1 0 -20 -42  10 20 .3 100 200 .7 ;30% choose between 10 and 20 and 70% between 100 and 200
    f2 0 8192 10 1			  ;sine wave

    i 1 0 5
    i 2 6 5
    e
    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like these:

     i1   184.61538
     i1   130.76923
     i1   169.23077
     i1    12.00000
    .......

    WARNING: Seeding from current time 3751086165

     i2   138.46154
     i2    12.00000
     i2   123.07692
     i2   161.53846
     i2   123.07692
     i2   153.84615
    ......

## See Also

cuserrnd, duserrnd

## Credits

Author: Gabriel Maldonado

New in Version 4.16

Prev | Up | Next
urandom | Home | vactrol