Skip to content

Instantly share code, notes, and snippets.

@lian
Created November 6, 2013 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lian/7346260 to your computer and use it in GitHub Desktop.
Save lian/7346260 to your computer and use it in GitHub Desktop.
ruby-shuffle-test.rb
require 'securerandom'
N = 100_000
A = %w(a b c)
Score = Hash.new { |h, k| h[k] = 0 }
N.times do
sorted = A.sort_by{ SecureRandom.random_bytes(4).unpack("I")[0] }
Score[sorted.join(" ")] += 1
end
Score.keys.sort.each do |key|
puts "#{key}: #{Score[key]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment