From: Stefan Arentz Date: 2003-07-08T10:21:42+09:00 Subject: Code Snippet: Array.shuffle Here is another small Ruby code snippet that extends the Array class. Use this to randomize the order of all entries in an Array. class Array def shuffle self.each_index { |i| r = rand(self.length - 1); self[i],self[r] = self[r],self[i] } end end Works like this: a = Array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.shuffle ==> [7, 10, 9, 6, 4, 8, 5, 3, 1, 2] S.