rnd
Prev | Orchestra Opcodes and Operators | Next

## rnd

rnd — Returns a random number in a unipolar range at the rate given by the input argument.

## Description

Returns a random number in a unipolar range at the rate given by the input argument.

## Syntax

    rnd(x) (init- or control-rate only)

Where the argument within the parentheses may be an expression. These value converters sample a global random sequence, but do not reference seed. The result can be a term in a further expression.

## Performance

Returns a random number in the unipolar range 0 to x.

## Examples

Here is an example of the rnd opcode. It uses the files rnd.orc and rnd.sco.

Example 328. Example of the rnd opcode.

    /* rnd.orc */
    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Generate a random number from 0 to 1.
      i1 = rnd(1)
      print i1
    endin
    /* rnd.orc */

    /* rnd.sco */
    ; Play Instrument #1 for one second.
    i 1 0 1
    ; Play Instrument #1 for one second.
    i 1 1 1
    e
    /* rnd.sco */

Its output should be:

    rnd at i-rate: 0.973500   rnd at k-rate: 0.139405
    rnd at i-rate: 0.973500   rnd at k-rate: 0.040065
    rnd at i-rate: 0.973500   rnd at k-rate: 0.412845
    rnd at i-rate: 0.973500   rnd at k-rate: 0.440650
    rnd at i-rate: 0.973500   rnd at k-rate: 0.663581
    rnd at i-rate: 0.973500   rnd at k-rate: 0.876723
    rnd at i-rate: 0.973500   rnd at k-rate: 0.302459
    rnd at i-rate: 0.973500   rnd at k-rate: 0.398580
    rnd at i-rate: 0.973500   rnd at k-rate: 0.448875
    rnd at i-rate: 0.973500   rnd at k-rate: 0.907728

## See Also

birnd

## Credits

Author: Barry L. Vercoe
MIT
Cambridge, Massachussetts
1997

Original Example written by Kevin Conder. Modified by John Harrison.

Prev | Up | Next
rms | Home | rnd31