Skip to content

Instantly share code, notes, and snippets.

@jan-g
Created January 30, 2018 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-g/e1dea1962fea4d6e445c8c463d17527d to your computer and use it in GitHub Desktop.
Save jan-g/e1dea1962fea4d6e445c8c463d17527d to your computer and use it in GitHub Desktop.
monte carlo for Alex
#!/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