Skip to content

Instantly share code, notes, and snippets.

@robinsloan
Created July 1, 2011 01:13
Show Gist options
  • Save robinsloan/1057675 to your computer and use it in GitHub Desktop.
Save robinsloan/1057675 to your computer and use it in GitHub Desktop.
Arghhhh
# 4<w<8, 1<y<10, x and z are 6-sided dice.
HOW_MANY = 100000
def range_rand(min,max)
min + rand(max-min)
end
def test_it
w = range_rand(4,8)
x = range_rand(1,6)
y = range_rand(1,10)
z = range_rand(1,6)
return ((w+x) > (y+z))
end
results = []
HOW_MANY.times do |test|
result = test_it
results << result
puts("test #{test}: "+result.to_s)
end
trues = results.select { |val| val == true }
falses = results.select { |val| val == false }
puts trues.size
puts falses.size
ratio = trues.size.to_f/results.size.to_f
puts ratio
puts "i am literally losing my mind"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment