User-Defined Opcode Database

RandomWalkK

Generate random walk at k-rate

Description

Generate random walk at k-rate. rnd31 outputs in range kstep and output is bound within imin and imax.

Syntax

kout RandomWalkK kstep, imin, imax, iseed

Initialization

imin - minimum of range of values

imax - maximum of range of values

iseed - seed for rnd31

Performance

kstep - kscl for rnd31. The generated random numbers are in the range -kstep to kstep. kstep must be less than (max-min)/2.

Code

```        opcode RandomWalkK, k, kiii
kstep, imin, imax, iseed        xin
k1      init (imin + imax) * 0.5
k2      rnd31 kstep, 0, iseed
k3      =  k1 + k2
k1      =  ((k3 < imin) || (k3 > imax) ? k1 - k2 : k3)
xout k1
endop ```

Examples

```<CsoundSynthesizer>
<CsOptions>
-d -m231 -H0
</CsOptions>
<CsInstruments>
sr      = 48000
ksmps   = 32
nchnls  = 1

opcode RandomWalkA, a, kiii
setksmps 1
kstep, imin, imax, iseed        xin
k1      init (imin + imax) * 0.5
k2      rnd31 kstep, 0, iseed
k3      =  k1 + k2
k1      =  ((k3 < imin) || (k3 > imax) ? k1 - k2 : k3)
aout    upsamp k1
xout aout
endop

opcode RandomWalkK, k, kiii
kstep, imin, imax, iseed        xin
k1      init (imin + imax) * 0.5
k2      rnd31 kstep, 0, iseed
k3      =  k1 + k2
k1      =  ((k3 < imin) || (k3 > imax) ? k1 - k2 : k3)
xout k1
endop

instr 1

kstep   linseg 0, p3/2, 2000, p3/2, 0
afoo    RandomWalkA kstep, -10000, 10000, 0
out afoo

endin
</CsInstruments>
<CsScore>
t 0 60
i 1 0 5
e
</CsScore>
</CsoundSynthesizer> ```

Credits

Istvan Varga

 Previous Home Next RandomWalkA ampdbN