spread() generates a Euclidean boolean ring for rhythmic hit placement in Sonic Pi
spread(k, n) returns a ring of k trues distributed as evenly as possible across n steps — the Euclidean rhythm algorithm. Used with tick and look to conditionally trigger samples: sample :bd if spread(3,8).tick. This maps directly onto standard Euclidean rhythm patterns (e.g., spread(3,8) = the tresillo). The spread fn is the Sonic Pi-idiomatic way to program polyrhythmic structures without manually encoding boolean patterns.
Examples
live_loop :drums do tick sample :bd_haus if spread(3,8).look sample :drum_snare_hard if spread(2,8).look sleep 0.25 end
Assessment
Use spread to create a 3-against-8 kick pattern alongside a 5-against-8 hihat. Explain what Euclidean distribution means in plain terms.