class Array
  def randomize
    self.sort_by { rand }    # sort by a key which is a
  end                        # random number
  def randomize!
    self.replace(self.randomize)
  end
end

x = [1, 2, 3, 4, 5]
y = x.randomize     # [3, 2, 4, 1 ,5]
x.randomize!        # x is now [3, 5, 4, 1, 2]

