random
Prev | Orchestra Opcodes and Operators | Next

## random

random — Generates a controlled pseudo-random number series between min and max values.

## Description

Generates is a controlled pseudo-random number series between min and max values.

## Syntax

    ares random kmin, kmax

    ires random imin, imax

    kres random kmin, kmax

## Initialization

imin -- minimum range limit

imax -- maximum range limit

## Performance

kmin -- minimum range limit

kmax -- maximum range limit

The random opcode is similar to linrand and trirand but sometimes I [Gabriel Maldonado] find it more convenient because allows the user to set arbitrary minimum and maximum values.

## Examples

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

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

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

    instr 1	;same values every time

    krnd random 100, 1000
         printk .5, krnd			; look
    aout oscili 0.8, 440+krnd, 1		; & listen
         outs aout, aout

    endin

    instr 2	;different values every time

    seed 0
    krnd random 100, 1000			; seed from system clock
         printk .5, krnd			; look
    aout oscili 0.8, 440+krnd, 1		; & listen
         outs aout, aout

    endin
    </CsInstruments>
    <CsScore>
    f 1 0 16384 10 1	;sine wave.

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

Its output should include lines like:

     i   1 time     0.00067:   894.58566
     i   1 time     0.50000:   748.44281
     i   1 time     1.00000:   328.29916

    WARNING: Seeding from current time 1656666052

     i   2 time     2.00067:   690.71466
     i   2 time     2.50000:   459.42445
     i   2 time     3.00000:   100.85594

## See Also

linrand, randomh, randomi, trirand

## Credits

Author: Gabriel Maldonado

Prev | Up | Next
randi | Home | randomh