# Information on the lists

Hi all ,information on the lists : I have a list of notes, I would like to randomly choose an item from the list but never the same element twice , is it possible to do this ?

What about using the .shuffle method to scramble of orrdered list of notes?
eg

``````n=scale(:c4,:major,num_octaves: 2) #list of notes to play (ordered)
l= n.length
puts l

scrambled = n.shuffle #scramble the list into a random order

l.times do |x| #play the list in the scrambled order
play scrambled[x],release: 0.1 #x increments each pass of the loop
sleep 0.1
end
``````

Thanks Robin, but your example does not work well as it may happen that the last note of the current list is equal to the first note of the new list after the shuffle function, then you play two equal notes while I want the current note is always different from the previous one.
The only way I’ve found is to use the while function, as in the example below, in this way the note chosen by the variable X is always different from the one chosen previously (this is good for the harmonic progression).

use_synth :piano

m = [55, 55, 57, 59].ring
n = [52,50,48]
x = 50

8.times do
play m.tick
sleep 0.5
end

live_loop :jjj do
puts x

8.times do
play m.tick
sleep 0.25
play x
sleep 0.25
end

y = x

while x == y
x = n.choose
end
end

Ah. I was assuming you knew all the notes you would use before you started. Your solution above just prevents two consecutive notes being the same. If you want to stop a note EVER being repeated, you could build a list of notes played and test if the next note chosen was in that list using the Ruby incude?. method. However this could get quite slow for long lists.
`if notelist.include? nextnote`

A tip to everybody :

Use 3 backticks at the beginning and at the end of a block of code to highlight it. A single backtick is for inline code.