Shuffle is not returning a shuffled list when used on a scale

I’m running 4.3.0 on Windows, and ran into a really odd issue with shuffle. For some reason, shuffle just returns the original, unshuffled list or ring when that list is a scale, or was copied from one.

Scale lists do seem to contain odd syntax, in that at the start they have the whole “SonicPi::Scale :root :name” section when inspected, which is not an addressable element, so I’m wondering if that’s why?

I should mention I’m a fairly new user to Sonic Pi, so it’s possible I’m missing something here - if so, please let me know. But I thought it worth posting here to confirm.

Here’s a short test which shows this in action - no audio, just using puts to print values to log:

#test case for scale shuffle behavior
#Same action is being performed on testscale, testlist and testring
#testlist and testring become shuffled
#testscale does not

#Note, it makes no difference whether the shuffle is
#performed as result=shuffle(list), or result=list.shuffle.

testscale = scale :c3, :major
testlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
testring = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
testring = testring.ring

live_loop :shuffletest do
testscale = shuffle (testscale)
puts "testscale after shuffle: "
puts testscale

testlist = shuffle (testlist)
puts "testlist after shuffle: "
puts testlist

testring = shuffle (testring)
puts "testring after shuffle: "
puts testring

sleep 1
end

Tested this on a Mac and with latest Tech preview. Same result. looks like this is a bug.
if you do
puts scale :c3, :major => (ring <SonicPi::Scale :C :major [48, 50, 52, 53, 55, 57, 59, 60])
note the <SonicP;;Scale :C :major before the list of notes.
This differs from a ring formed by [1,2,3,4].ring => (ring 1,2,3,4)

You can get round it by using something like
puts scale( :c3, :major).reverse.reverse => (ring 48, 50, 52, 53, 55, 57, 59, 60)

since you are shuffling just one reverse would do.

puts scale( :c3, :major).reverse.shuffle =>(ring 59, 60, 50, 55, 52, 48, 57, 53) for example.

I will investigate further. It seems just to be .shuffle which has the problem.

Incidentally try using three back ticks ``` on the lines before and after your block of code. It formats it nicely and makes it easier to copy.

Thanks! I’ll try your solution

I ended up working around by writing a method to take a ring, iterate through its elements and return them as a new ring, which allowed me to make scale/chord rings shufflable. Really inefficient though, so your workaround looks a lot cleaner

I have posted this as an issue on the sonic pi github site. (I credited you with raising the issue)