Randomizing an Array Help


#1

(sorry if I posted this twice, google groups is not working well, I
think)

I’m trying to randomize an array, and this is what I have:

arr_set_unordered = randomizer(arr_set)

def randomizer(arr)
result = arr.collect { arr.slice!(rand arr.length) }
end

It does randomize it, but it only returns 3 values instead of the 5
values that I’m expecting. Any ideas why?

Thank you!


#2

a = [1,2,3,4,5]
a.sort_by {rand}
=> 3,1,5,2,4