Created
January 30, 2018 15:38
-
-
Save jan-g/e1dea1962fea4d6e445c8c463d17527d to your computer and use it in GitHub Desktop.
monte carlo for Alex
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
#!/usr/bin/env python3 | |
import random | |
import collections | |
# t is a map of n -> count, where n is the size of the repeat, and count is the | |
# number of rolls that fall into that category | |
t = collections.Counter() | |
for r in range(1, 100000): | |
# Select 100 numbers in the range [0, 2000) | |
c = collections.Counter(random.choices(range(2000), k=100)) | |
# c is a map of die roll -> count of occurrences. | |
# Make a histogram of the *values* | |
h = collections.Counter(c.values()) | |
t.update(h) | |
print(c) | |
print(h) | |
print(t) | |
print({n: t[n] / r for n in t}) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment