Module: Rearranging
- Defined in:
- lib/rearranging.rb
Overview
Functions which rearrange an array.
Instance Method Summary collapse
Instance Method Details
#randomize ⇒ Object
… guess
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |