P
Pat Maddox
I did some searching on how to shuffle an array, and found
sort_by{rand}. However, if I call it, it doesn't make a change to my
array at all. I've got a class like this
class MyClass
def initialize
# Populate the array
@my_array =3D Array.new
...
end
def shuffle!
@my_array.sort_by{rand}
end
end
If I call shuffle! from my code, the array's elements are still in the
order that they were created. Why are they not being shuffled like I
want?
sort_by{rand}. However, if I call it, it doesn't make a change to my
array at all. I've got a class like this
class MyClass
def initialize
# Populate the array
@my_array =3D Array.new
...
end
def shuffle!
@my_array.sort_by{rand}
end
end
If I call shuffle! from my code, the array's elements are still in the
order that they were created. Why are they not being shuffled like I
want?