Sha256: 9e673e4a302daf862606e17c7e38bd82d2805dbb900da14aed66dd8f9f164eac

Contents?: true

Size: 233 Bytes

Versions: 17

Compression:

Stored size: 233 Bytes

Contents

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

    def shuffle
      dup.shuffle!
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spruz-0.2.13 lib/spruz/shuffle.rb
spruz-0.2.12 lib/spruz/shuffle.rb
spruz-0.2.11 lib/spruz/shuffle.rb
spruz-0.2.10 lib/spruz/shuffle.rb
spruz-0.2.9 lib/spruz/shuffle.rb
spruz-0.2.8 lib/spruz/shuffle.rb
spruz-0.2.7 lib/spruz/shuffle.rb
spruz-0.2.6 lib/spruz/shuffle.rb
spruz-0.2.5 lib/spruz/shuffle.rb
spruz-0.2.2 lib/spruz/shuffle.rb
spruz-0.2.1 lib/spruz/shuffle.rb
spruz-0.2.0 lib/spruz/shuffle.rb
spruz-0.1.5 lib/spruz/shuffle.rb
spruz-0.1.3 lib/spruz/shuffle.rb
spruz-0.1.2 lib/spruz/shuffle.rb
spruz-0.1.1 lib/spruz/shuffle.rb
spruz-0.1.0 lib/spruz/shuffle.rb