randc
Prev | Orchestra Opcodes and Operators | Next

## randc

randc — Generates a controlled random number series with cubic interpolation between each new number.

## Description

Generates a controlled random number series with cubic interpolation between each new number.

## Syntax

    ares randc xamp, xcps [, iseed] [, isize] [, ioffset]

    kres randc kamp, kcps [, iseed] [, isize] [, ioffset]

## Initialization

iseed (optional, default=0.5) -- seed value for the recursive pseudo-random formula. A value between 0 and +1 will produce an initial output of kamp * iseed. A negative value will cause seed re-initialization to be skipped. A value greater than 1 will seed from system time, this is the best option to generate a different random sequence for each run.

isize (optional, default=0) -- if zero, a 16 bit number is generated. If non-zero, a 31-bit random number is generated. Default is 0.

ioffset (optional, default=0) -- a base value added to the random result.

## Performance

kamp, xamp -- range over which random numbers are distributed.

kcps, xcps -- the frequency which new random numbers are generated.

The internal pseudo-random formula produces values which are uniformly distributed over the range kamp to -kamp. rand will thus generate uniform white noise with an R.M.S value of kamp / root 2.

The remaining units produce band-limited noise: the kcps and xcps parameters permit the user to specify that new random numbers are to be generated at a rate less than the sampling or control frequencies. randi will produce straight-line interpolation between each new number and the next.

## Examples

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

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

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

    ; by Menno Knevel - 2024

    instr 1	;same values every time

    krnd randc 100, 10
         printk .5, krnd			; look
    aout oscili 0.8, 440+krnd		; & listen
         outs aout, aout

    endin

    instr 2	;different values every time

    krnd randc 100, 10, 10			; seed from system clock
         printk .5, krnd			; look
    aout oscili 0.8, 440+krnd		; & listen
         outs aout, aout

    endin
    </CsInstruments>
    <CsScore>
    i 1 0 3
    i 2 4 3
    e
    </CsScore>
    </CsoundSynthesizer>

The example will produce the following output:

     i   1 time     0.00000:    50.00305
     i   1 time     0.50068:    68.16267
     i   1 time     1.00136:   -94.61682
     i   1 time     1.50204:   -74.38840
    ....

    WARNING: Seeding from current time 67726716

     i   2 time     4.00036:    79.19006
     i   2 time     4.50104:   -47.46559
     i   2 time     5.00172:    74.73582
     i   2 time     5.50240:    65.35726
    ....

## See also

Random (Noise) Generators randh, rand

Prev | Up | Next
rand | Home | randh