How to randomly sort (scramble) an array in Ruby?

arrays, random, ruby, shuffle

Solution

Built in now:

[1,2,3,4].shuffle => [2, 1, 3, 4]
[1,2,3,4].shuffle => [1, 3, 2, 4]

Problem

I'd like to have my array items scrambled. Something like this: ``` [1,2,3,4].scramble => [2,1,3,4] [1,2,3,4].scramble => [3,1,2,4] [1,2,3,4].scramble => [4,2,3,1] ``` and so on, randomly

Original source