Module: RubyTorrent::ArrayShuffle

Defined in:
lib/rubytorrent/util.rb

Instance Method Summary collapse

Instance Method Details

#shuffleObject



173
174
175
# File 'lib/rubytorrent/util.rb', line 173

def shuffle
  self.clone.shuffle! # dup doesn't preserve shuffle! method
end

#shuffle!Object



166
167
168
169
170
171
# File 'lib/rubytorrent/util.rb', line 166

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