Module: Tins::Shuffle

Defined in:
lib/tins/shuffle.rb

Instance Method Summary collapse

Instance Method Details

#shuffleObject



12
13
14
# File 'lib/tins/shuffle.rb', line 12

def shuffle
  dup.shuffle!
end

#shuffle!Object

:nocov:



4
5
6
7
8
9
10
# File 'lib/tins/shuffle.rb', line 4

def shuffle!
  (size - 1) .downto(1) do |i|
    j = rand(i + 1)
    self[i], self[j] = self[j], self[i]
  end
  self
end