randomh

randomh — Generates random numbers with a user-defined limit and holds them for a period of time.

Description

Generates random numbers with a user-defined limit and holds them for a period of time.

Syntax

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

Initialization

imode (optional, default=0) -- generation mode of the first output value (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 randomh opcode is similar to randh 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. Then, the normal process takes place with a new random number generated and held every 1/kcps (resp. 1/xcps) seconds.

When imode = 2, the ifirstval argument value is outputted during 1/kcps (resp. 1/xcps) seconds at the beginning of the note. Then, the normal process takes place with a new random number generated and held every 1/kcps (resp. 1/xcps) seconds.

When imode = 3, the generation process begins with a random value from the initialization time.

Examples

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

Example 899. Example of the randomh 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    ;;;realtime audio out
; For Non-realtime ouput leave only the line below:
; -o randomh.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; by Kevin Conder & Menno Knevel, adapted for new args by Francois Pinot.

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

seed 0

instr 1

kmin    init 220; Choose a random frequency between 220 and 440 Hz.
kmax    init 440
kcps    init 10; Generate new random numbers at 10 Hz.
imode   =    p4
ifstval =    p5
  
printf_i "\nMode: %d\n", 1, imode
k1 randomh kmin, kmax, kcps, imode, ifstval
printk2 k1
asig    poscil  1, k1
outs    asig, asig
endin

</CsInstruments>
<CsScore>
; each time with a different mode.
i 1 0 1
i 1 2 1 2 330
i 1 4 1 3
e
</CsScore>
</CsoundSynthesizer>


Its output should include lines like this:

Mode: 0
 i1   220.00000
 i1   396.26079
 i1   240.75446
 i1   364.24577
    ...

Mode: 2
 i1   330.00000
 i1   416.50935
 i1   356.11619
 i1   433.59324
    ...

Mode: 3
 i1   261.17741
 i1   402.00891
 i1   393.86592
 i1   307.19839
    ...

Two musical examples featuring the randomh opcode: FtmorfRandomh_Cucchi.csd and Ftmorf_Cucchi.csd, both by Stefano Cucchi.

See also

Random (Noise) Generators

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.