duserrnd
Prev | Orchestra Opcodes and Operators | Next

## duserrnd

duserrnd — Discrete USER-defined-distribution RaNDom generator.

## Description

Discrete USER-defined-distribution RaNDom generator.

## Syntax

    aout duserrnd ktableNum

    iout duserrnd itableNum

    kout duserrnd 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

duserrnd (discrete user-defined-distribution random generator) generates random values according to a discrete random distribution created by the user. The user can create the discrete distribution histogram by using GEN41. In order to create that table, the user has to define an arbitrary amount of number pairs, the first number of each pair representing a value and the second representing its probability (see GEN41 for more details).

When used as a function, the rate of generation depends by the rate type of input variable XtableNum. In this case it can be embedded into any formula. Table number can be varied at k-rate, allowing to change the distribution histogram during the performance of a single note. duserrnd is designed be used in algorithmic music generation.

duserrnd can also be used to generate values following a set of ranges of probabilities by using distribution functions generated by GEN42 (See GEN42 for more details). In this case, in order to simulate continuous ranges, the length of table XtableNum should be reasonably big, as duserrnd does not interpolate between table elements.

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 duserrnd opcode. It uses the file duserrnd.csd.

Example 235. Example of the duserrnd 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 duserrnd.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

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

    instr 1

    k1   duserrnd 1
         printk 0, k1
    asig poscil .5, 220*k1, 2	;multiply frequency with random value
         outs asig, asig

    endin
    </CsInstruments>
    <CsScore>
    f1 0 -20 -41  2 .1 8 .9	;choose 2 at 10% probability, and 8 at 90%

    f2 0 8192 10 1

    i1 0 2
    e
    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like these:

    i   1 time     0.00067:     8.00000
    i   1 time     0.00133:     8.00000
    i   1 time     0.00200:     8.00000
    i   1 time     0.00267:     8.00000
    i   1 time     0.00333:     2.00000
    i   1 time     0.00400:     8.00000
    i   1 time     0.00533:     8.00000
    i   1 time     0.00600:     8.00000
    ..........

## See Also

cuserrnd, urd

## Credits

Author: Gabriel Maldonado

New in Version 4.16

Prev | Up | Next
dumpk4 | Home | dust