module Rearranging

Functions which rearrange an array.

Public Instance Methods

randomize() click to toggle source

… guess

# File lib/rearranging.rb, line 31
def randomize
  if( self.respond_to?(:to_ary) )
    size = self.length
    original_list = self.dup
    random_list = Array.new
    while(random_list.size < size) do
      srand(Time::now.nsec)
      index = rand(original_list.size)
      item = original_list.delete_at(index) 
      random_list << item
    end
    self.replace(random_list)
  else
    raise TypeError.new('can only randomize Array, not ' << self.class.name)
  end
end