Skip to content

Instantly share code, notes, and snippets.

@spangenberg
Created October 13, 2014 16:25
Show Gist options
  • Save spangenberg/92999170bc7959a07f6d to your computer and use it in GitHub Desktop.
Save spangenberg/92999170bc7959a07f6d to your computer and use it in GitHub Desktop.
Normal distribution
n = 6 * 10_000
loop do
hash = Hash.new { |hash, key| hash[key] = 0 }
n.times.each { hash[rand(1..6)] += 1 }
hash = Hash[hash.reduce({}) { |memo, (key, value)| memo[key] = value / (n / 100.0); memo }.sort]
if hash.values.reduce(&:+) == 100.0
hash.each { |key, value| puts "#{key} - #{value}%" }
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment