Created
February 12, 2012 11:43
-
-
Save bootandy/1808133 to your computer and use it in GitHub Desktop.
Python. Random dice rolling sim.
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
import random | |
def role(): | |
return int(random.random() * 6) + 1 | |
def main(): | |
hits5plus = 0 | |
hits6 = 0 | |
roles = 10000 | |
print "Which is more likely a dice role of 5 or 6. Or rolling 2 dice and getting at least 1 6?" | |
print "rolling dice "+str(roles)+" times" | |
for i in range(0, roles): | |
if role() >= 5: | |
hits5plus += 1 | |
if role() >= 6 or role() >= 6: | |
hits6 += 1 | |
print "hits 5+ " + str(hits5plus) | |
print "hits 2 dice 6+ " + str(hits6) | |
print "5+ prob: " + str( hits5plus*100/roles ) + "%" | |
print "2 X 6+ prob: " + str( hits6*100/roles ) + "%" | |
# This is the standard boilerplate that calls the main() function. | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment