study 08 of 10
Chance you can repeat
Random choices are where scripts surprise you. They are also where you want control: keep the variation you liked, come back to it tomorrow. This study covers OType's random values, its lists, and the seeds that make chance repeatable.
Random values
| write | gives |
|---|---|
rnd n | 0 to n − 1 |
rrand a b | a to b, both included |
toss | 0 or 1 |
chance p | 1 with p % chance, else 0 |
prob p: | the modifier you know: run the line with p % chance |
Lists
A list is a few numbers between braces, up to sixteen: {60 90 127}. Lists are constants, written
in the script; usually you name them with const. Three operations read them: pick list
(one element at random), at list n (the n-th, from 1) and len list (how many).
const vols {60 90 127}
def rnd_hats
menu "LEARN" >> "RND HATS"
tr.clr
l 1 16:
if chance 60:
tr.add i
pl.set i amp.vol pick volsOutput · what the simulator prints for $ otype.py run rnd_hats -v --seed 5
rnd_hats seed 5 (--seed) pattern A01 len 16 (default) track 1
T1 1 5 9 13
...XXX..XXXXXX.X
step 4: amp.vol 90 step 5: amp.vol 60 step 6: amp.vol 60 step 9: amp.vol 60
step 10: amp.vol 90 step 11: amp.vol 60 step 12: amp.vol 90 step 13: amp.vol 60
step 14: amp.vol 127 step 16: amp.vol 60
X trig ! one-shot o trigless trig - trigless lock l locks only . none
part: tempo 120
cost: 244/304 random draws: rand 10 toss 16 prob 0 drunk 0 file 0Some operations draw a value for every step of the context at once: pl.rnd p locks parameter
p at random on each trig, smp.rnd a b locks a sample slot between a and
b. They save you a loop.
Seeds
Each press draws new numbers. seed n fixes the draws: from that line on, the same n
always gives the same results, on the unit as in the simulator. Make the seed a setting, and the player can browse
variations and come back to the one they liked:
def variations
menu "LEARN" >> "VARIATIONS"
param pick_no 1 1 99
seed pick_no
tr.clr
l 1 16: prob 40: tr.add iOutput · what the simulator prints for $ otype.py run variations
variations seed 1 (--seed) pattern A01 len 16 (default) track 1
T1 1 5 9 13
...X...XX.....XX
X trig ! one-shot o trigless trig - trigless lock l locks only . none
part: tempo 120
cost: 149/193 random draws: rand 0 toss 0 prob 16 drunk 0 file 0A seed holds until the end of the block it is in; outside it, the draws go on as before. That lets you fix one part of a function and leave the rest free.
Chance in OType comes from five separate streams: one for rnd rrand pick, one for
toss chance, one for prob, one for drunk, and one for the files on the
card. Adding a prob line therefore does not change what the next rrand gives.
seed sets all five; rand.seed, toss.seed, prob.seed,
drunk.seed and file.seed set one each.
A/B with a seed
Combine a seed with flip from variables and memory: one press gives
variation 7, the next one the pattern without randomness, and so on.
def ab_locks
menu "LEARN" >> "A/B FX"
seed ? flip 7 0
steps has.trig:
pl.rnd fx1 1What you learned
rnd·rrand·toss·chance- random values
{…}·pick·at·len- constant lists and their reading
pl.rnd·smp.rnd- a random lock on every trig of the context
seed n- the same draws for the same n, until the end of the block
- streams
- five independent sources;
rand.seedand the others seed one
Try it
- Run
variationson the computer with--param pick_no=2, then 3: each pattern is always the same. - Put the
seedofrnd_hatsin a block around the trigs only, so the volumes stay free. - Use
at vols rrand 1 3instead ofpick vols. Is it the same?