Last active
September 27, 2015 10:47
-
-
Save danielmiessler/1257226 to your computer and use it in GitHub Desktop.
A simple dicerolling program.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def sum | |
self.inject{|sum,x| sum + x } | |
end | |
end | |
nod = 10 | |
noc = 1000000 | |
target = 20 | |
rolls = [] | |
dicetype = 6 | |
success = 0 | |
failure = 0 | |
noc.times do | |
nod.times do | |
rolls.push(1 + rand(dicetype)) | |
end | |
if rolls.sum >= target : | |
success += 1 | |
else | |
failure += 1 | |
end | |
rolls.clear | |
end | |
percentage = success.to_f / noc.to_f * 100 | |
print "When rolling one million times on #{nod} dice with a target of #{target}, there were #{success} successes and #{failure} failures, which is #{percentage}%." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment