home/ atoms/ sonic-pi-random-seed

use_random_seed resets Sonic Pi's random stream so a live_loop produces a repeatable random pattern

Placing use_random_seed N at the top of a live_loop body resets the random stream to a fixed starting position at the start of every iteration. All subsequent random calls in that iteration — choose, rrand, shuffle, rand, etc. — then follow the same sequence each loop, so a ‘random’ melody repeats identically every cycle. Changing N instantly generates a different but internally consistent pattern, which is the core of Sonic Pi’s deterministic ‘explore seeds’ composition method: try seeds, keep the one you like, and share the number so others hear exactly what you heard. The placement matters: with the seed inside the loop the pattern re-resets and repeats every iteration; move use_random_seed outside the live_loop and the reset no longer happens each cycle, so the pattern evolves instead of repeating.

Examples

live_loop :riff do
  use_random_seed 3000
  notes = (scale :e3, :minor_pentatonic, num_octaves: 2).shuffle.take(8)
  8.times do
    play notes.tick, release: 0.1
    sleep 0.125
  end
end

Changing 3000 to 43 yields a completely different but repeatable 8-note melody from the same scale.

Assessment

Use use_random_seed inside a live_loop to generate a repeatable 8-note melody, then find a seed you like. Explain why changing the seed number produces a completely different melody from the same scale, and what changes about the behaviour when you move use_random_seed outside the live_loop.

“when you share it with others, they will hear exactly what you heard too”
corpus · sonic-pi-built-in-tutorial · chunk 10
“just by changing one number (the random seed), you can explore as many melodic combinations as you can imagine”
corpus · sonic-pi-built-in-tutorial · chunk 27