# Choose - Sleep with total of beat

Hi all,

I was wondering how you would do that, the best way:
Here is a simple code:

live_loop :test do
16.times do
play scale(:c4, :minor).choose
sleep [0.125, 0.25, 0.5, 0.75, 1].choose
end
end

How can I do to be sure that the 16 times duration is always equal to 8 beat. I’d like the sum of the 16 “choose” always do 8

Any Idea?

One option would be to make an array of 16 numbers that add up to 8, and shuffle them so that they play in a random order, but the total time will always be the same. Something like this maybe:

``````live_loop :test do
times = [1, 0.25, 0.25, 0.25, 0.75, 0.5, 0.5, 0.5] * 2
times.shuffle.each do |t|
play scale(:c4, :minor).choose
sleep t
end
end
``````
2 Likes
``````loop do
play scale(:c4, :minor).choose, amp: choose([0,0,0,1])
sleep 0.125
end``````
1 Like

clever solution. Perhaps better as a live loop so it can be used with other bits.
I played both solutions (so far) together. Sounded nice.

``````live_loop :test do
times = [1, 0.25, 0.25, 0.25, 0.75, 0.5, 0.5, 0.5] * 2
times.shuffle.each do |t|
play scale(:c4, :minor).choose
sleep t
end
end

live_loop :test2 do
play scale(:c4, :minor).choose, amp: choose([0,0,0,1])
sleep 0.125
end
``````

Thank You !!! ( Smiley Here )

``````
a = [0.125,0.25,0.5,1]
t = 0
live_loop :a do
play scale(:c4,:minor).choose
sleep b = a.choose
t +=b
puts t
if t >=15
play scale(:c4,:minor).choose
sleep 16-t
t = 0
end
end
``````
1 Like