Last active
December 13, 2015 19:49
-
-
Save funkaoshi/4965672 to your computer and use it in GitHub Desktop.
I was curious what the distribution was when you ask a player to try and roll under a D&D attribute, in general.
This file contains hidden or 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 collections | |
import random | |
def d(die): return random.randint(1, die) | |
def xdy(x,y): return sum(d(y) for _ in xrange(x)) | |
# How many times we will peform our simulation | |
TEST_RUN = 1000000 | |
# Roll up an attribute score 3d6 and proceed to try and roll under it, storing | |
# the results as a histogram. | |
results = collections.Counter(xdy(3,6) - d(20) for _ in xrange(TEST_RUN)) | |
sucesses = sum(y for x, y in results.iteritems() if x < 0) | |
fails = TEST_RUN - sucesses | |
print "Out of %d rolls, we have %d sucesses and %d fails." % (TEST_RUN, sucesses, fails) | |
print "--------------" | |
for x, y in results.iteritems(): | |
if x >= 0: | |
print "%2d -> %d" % (x, y) | |
print "--------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sample run: