use_random_seed 1
puts rand
puts rand
use_random_seed 1
puts rand
with_random_seed 1 do
puts rand
puts rand
end
puts rand
|
# reset random seed to 1
# => 0.417022004702574
#=> 0.7203244934421581
# reset it back to 1
# => 0.417022004702574
# reset seed back to 1 just for this block
# => 0.417022004702574
#=> 0.7203244934421581
# => 0.7203244934421581
# notice how the original generator is restored
|
notes = (scale :eb3, :minor_pentatonic, num_octaves: 2)
with_fx :reverb do
live_loop :repeating_melody do
with_random_seed 300 do
8.times do
play notes.choose, release: 0.1
sleep 0.125
end
end
play notes.choose, amp: 1.5, release: 0.5
end
end
|
# Generating melodies
# Create a set of notes to choose from.
# Scales work well for this
# Create a live loop
# Set the random seed to a known value every
# time around the loop. This seed is the key
# to our melody. Try changing the number to
# something else. Different numbers produce
# different melodies
# Now iterate a number of times. The size of
# the iteration will be the length of the
# repeating melody.
# 'Randomly' choose a note from our ring of
# notes. See how this isn't actually random
# but uses a reproducible method! These notes
# are therefore repeated over and over...
# Note that this line is outside of
# the with_random_seed block and therefore
# the randomisation never gets reset and this
# part of the melody never repeats.
|