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 file rnd.csd.

Example 856. Example of the rnd 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
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o rnd.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Andres Cabrera 2010

    sr = 44100
    ksmps = 4410
    nchnls = 1
    0dbfs = 1

    instr 1
    	; Generate a random number from 0 to 10.
    	irand = rnd(10)
    	print irand
    endin

    instr 2
    	klimit init 10
    	krand = rnd(klimit)
    	printk 0, krand
    endin

    </CsInstruments>
    <CsScore>

    i 1 0 1  ; Generate 1 number
    i 1 0 1  ; Generate another number
    i 1 0 1  ; yet another number

    i 2 2 1  ; 1 second prints 9 values (kr = 10)
    e

    </CsScore>
    </CsoundSynthesizer>

Its output should be:

    SECTION 1:
    new alloc for instr 1:
    instr 1:  irand = 9.735
    new alloc for instr 1:
    instr 1:  irand = 1.394
    new alloc for instr 1:
    instr 1:  irand = 7.695
    midi channel 1 now using instr 1
    B  0.000 ..  2.000 T  2.000 TT  2.000 M:  0.00000
    new alloc for instr 2:
     i   2 time     2.10000:     5.25005
     i   2 time     2.20000:     6.22665
     i   2 time     2.30000:     9.69511
     i   2 time     2.40000:     7.16822
     i   2 time     2.50000:     9.45134
     i   2 time     2.60000:     1.34123
     i   2 time     2.70000:     2.09879
     i   2 time     2.80000:     2.36001
     i   2 time     2.90000:     0.03553

## See Also

birnd

## Credits

Author: Barry L. Vercoe
MIT
Cambridge, Massachussetts
1997

Prev | Up | Next
rms | Home | rnd31