Randomness and Seeding
Randomness can describe a repeatable composition or a decision made anew on each performance. The choice determines whether restarting or seeking brings back the same musical result.
A seed identifies a repeatable choice
Section titled “A seed identifies a repeatable choice”The seeded helpers in std/random return the same result for the same seed and arguments. A
constant seed therefore repeats one choice. Using the cycle number as the seed varies that choice
between cycles while preserving it when the same cycle is visited again.
use "std/random" { choose };let candidates = #[60, 64, 67, 71];assert choose(8, candidates) == choose(8, candidates);print(choose(8, candidates));Repeatability depends on the inputs too. Editing the candidate notes, weights or generator changes the composition even when the seed is unchanged. Independent musical parts can use deliberately different seed expressions instead of all drawing from the same cycle seed.
Pattern variation belongs to musical position
Section titled “Pattern variation belongs to musical position”Transforms such as .degrade() and .humanize() derive variation from event positions, so the
same position gives the same variation. Stateful generators replay their progression to answer
queries at a later cycle. These mechanisms let the scheduler revisit musical positions without
letting the act of querying change the music.
A custom query should preserve that property when repeatable playback matters. Unseeded random calls or mutable state outside the query can make the answer depend on evaluation order.
Unseeded choices are a performance decision
Section titled “Unseeded choices are a performance decision”rand_true() and choose_true() choose anew on each call. Re-running setup can therefore produce a
different result; invoking them inside a callback can produce a different performance at the same
cycle. They intentionally give up seekability, and they are appropriate when that variation is
the result you want.
How Patterns Work explains queries and replay. Make a Reproducible Random Choice shows seed choices, and Random lists the helpers.