randomi

randomi — Generates a user-controlled random number series with interpolation between each new number.

Description

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

Syntax

ares randomi kmin, kmax, xcps [,imode] [,ifirstval]
kres randomi kmin, kmax, kcps [,imode] [,ifirstval]

Initialization

imode (optional, default=0) -- first interpolation cycle mode (see below)

ifirstval (optional, default=0) -- first output value

Performance

kmin -- minimum range limit

kmax -- maximum range limit

kcps, xcps -- rate of random break-point generation

The randomi opcode is similar to randi but allows the user to set arbitrary minimum and maximum values.

When imode = 0 (the default), the kmin argument value is outputted during 1/kcps (resp. 1/xcps) seconds at the beginning of the note, before the first random number is generated. Then the normal interpolation process takes place, first between kmin and the first random number generated, and then between successive generated random numbers, each interpolation cycle having a duration of 1/kcps (resp. 1/xcps) seconds.

When imode = 1, a random number is generated at initialization and interpolation begins immediately between the kmin argument value and that random number.

When imode = 2, a random number is generated at initialization and interpolation begins immediately between the ifirstval argument value and that random number.

When imode = 3, two random numbers are generated at initialization as breakpoints for the first interpolation cycle.

Examples

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

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

; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

     seed 0
     
; Instrument #1.
instr 1
  ; Choose a random frequency between 220 and 440.
  ; Generate new random numbers at 10 Hz.
  kmin    init 220
  kmax    init 440
  kcps    init 10
  imode   =    p4
  ifstval =    p5
  
     printf_i "\nMode: %d\n", 1, imode
  k1 randomi kmin, kmax, kcps, imode, ifstval
     printks "k1 = %f\n", 0.1, k1
endin

</CsInstruments>
<CsScore>

; Play Instrument #1 for one second.
; each time with a different mode.
i 1 0 1
i 1 1 1 1
i 1 2 1 2 330
i 1 3 1 3
e

</CsScore>
</CsoundSynthesizer>


Its output should include lines like this:

Mode: 0
k1 = 220.000000
k1 = 220.000000
k1 = 220.146093
k1 = 246.827703
k1 = 395.595775
    ...

Mode: 1
k1 = 220.000000
k1 = 224.325329
k1 = 274.370074
k1 = 343.216049
k1 = 414.324347
    ...

Mode: 2
k1 = 330.000000
k1 = 292.628171
k1 = 334.519777
k1 = 290.610602
k1 = 394.905366
    ...

Mode: 3
k1 = 360.727674
k1 = 431.680412
k1 = 380.625254
k1 = 289.267139
k1 = 303.038109
    ...

See Also

randi, random, randomh

Credits

Author: Gabriel Maldonado

Arguments imode and ifirstval added by François Pinot, Jan. 2011, after a discussion with Peiman Khosravi on the csnd list.

Example written by Kevin Conder, adapted for new args by François Pinot.