Skip to content

Instantly share code, notes, and snippets.

@bschaeffer
Created August 16, 2012 03:42
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 bschaeffer/3366391 to your computer and use it in GitHub Desktop.
Save bschaeffer/3366391 to your computer and use it in GitHub Desktop.
How random is Array.sample... DUH DUH duhhh
times = ARGV[0].to_i
range = 1..20
counts = Hash[range.to_a.map{|i| [i, 0]}]
times.times do
i = range.to_a.sample
counts[i] = counts[i] + 1
end
counts.each_pair { |k,v| puts "#{k.to_s.ljust(range.max.length)} => #{v}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment