I was going to post a function I use in custom functions, but realized that there are probably better ways of doing this and I wanted see if anyone had any ideas.
I really like being able to generate random persistent sequences, for example, shuffling a pattern and having that particular shuffle repeat. I made a custom function I call
lock which uses
repeatCycles with an arbitrarily large number.
lock n offset p = slow n $ repeatCycles 10000 $ fast n $ (offset <~) p
This works in that it 'locks in' any randomness in a loop that is n cycles long, and allows me vary the random pattern by changing the offset value.
I'm not crazy about the
repeatCycles 10000 which feels like a code smell, but more importantly, it doesn't let me use patterns for the offset values in a predictable way. I might find two different offset vales that produce interesting sequences, for example 0 and 1, and set it to either value, but I can't set it to alternate between the two sequences produced by those offsets.
E.g., I can make two patterns:
d1 $ lock 1 "0" $ s "arpy*4" # n (irand 8)
d1 $ lock 1 "1" $ s "arpy*4" # n (irand 8)
d1 $ lock 2 "<0 1>" $ s "arpy*4" # n (irand 8)
won't alternate between the two. I can easily see the reason why: the random values used in the 2nd cycle won't be the same as the random values in the first cycle, but if I loop every cycle then I can't pattern any variation.
Does anyone have any suggestion for how I can accomplish this (I've also experimented with using
qtrigger in the function but either I'm doing it wrong or it's not what I need)? Or alternatively, other strategies for getting repeatable bits of randomness that can patterned together. Thanks!