cuserrnd
Prev | Orchestra Opcodes and Operators | Next

## cuserrnd

cuserrnd — Continuous USER-defined-distribution RaNDom generator.

## Description

Continuous USER-defined-distribution RaNDom generator.

## Syntax

    aout cuserrnd kmin, kmax, ktableNum

    iout cuserrnd imin, imax, itableNum

    kout cuserrnd kmin, kmax, ktableNum

## Initialization

imin -- minimum range limit

imax -- maximum range limit

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

kmin -- minimum range limit

kmax -- maximum range limit

cuserrnd (continuous user-defined-distribution random generator) generates random values according to a continuous random distribution created by the user. In this case the shape of the distribution histogram can be drawn or generated by any GEN routine. The table containing the shape of such histogram must then be translated to a distribution function by means of GEN40 (see GEN40 for more details). Then such function must be assigned to the XtableNum argument of cuserrnd. The output range can then be rescaled according to the Xmin and Xmax arguments. cuserrnd linearly interpolates between table elements, so it is not recommended for discrete distributions (GEN41 and GEN42).

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

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

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

    instr 1	; every run time same values

    kuser cuserrnd 0, 100, 1
          printk .2, kuser
    asig  poscil .5, 220+kuser, 3
          outs asig, asig
    endin

    instr 2	; every run time different values

          seed 0
    kuser cuserrnd 0, 100, 1
          printk .2, kuser
    asig  poscil .5, 220+kuser, 3
          outs asig, asig
    endin
    </CsInstruments>
    <CsScore>
    f 1 0 16 -7 1 4 0 8 0 4 1	;distrubution using GEN07
    f 2 0 16384 40 1		;GEN40 is to be used with cuserrnd
    f 3 0 8192 10 1			;sine

    i 1 0 2
    i 2 3 2
    e
    </CsScore>
    </CsoundSynthesizer>

Its output should include lines like these:

     i   1 time     0.00067:    53.14918
     i   1 time     0.20067:     0.00000
     i   1 time     0.40067:     0.00000
     i   1 time     0.60067:    96.80406
     i   1 time     0.80067:    94.20729
     i   1 time     1.00000:     0.00000
     i   1 time     1.20067:    86.13032
     i   1 time     1.40067:    31.37096
     i   1 time     1.60067:    70.35889
     i   1 time     1.80000:     0.00000
     i   1 time     2.00000:    49.18914

    WARNING: Seeding from current time 2006647442

     i   2 time     3.00067:    21.45002
     i   2 time     3.20067:    44.32333
     i   2 time     3.40067:    46.05420
     i   2 time     3.60000:     0.00000
     i   2 time     3.80067:    41.32175
     i   2 time     4.00000:     0.00000
     i   2 time     4.20000:    63.72019
     i   2 time     4.40067:     0.00000
     i   2 time     4.60067:     0.00000
     i   2 time     4.80067:     0.00000
     i   2 time     5.00000:    74.49330

## See Also

duserrnd, urd

## Credits

Author: Gabriel Maldonado

New in Version 4.16

Prev | Up | Next
ctrlinit | Home | dam