Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import uniform as r
- import matplotlib.pyplot as plt
- import numpy as np
- plt.figure(1)
- for numrolls in range(1, 10):
- plt.subplot(1, 9, numrolls)
- mind = 50
- maxd = 250
- samplesize = 1000000
- rolls = []
- for i in range(samplesize):
- roll = []
- for ii in range(numrolls):
- roll.append(r(mind, maxd))
- rolls.append(np.average(roll))
- normal = np.random.normal(loc=(mind+maxd)/2, scale=(maxd-mind)/7, size=samplesize)
- plt.hist(normal, bins=(maxd-mind)/3, alpha=0.5, label="normal")
- plt.hist(rolls, bins=(maxd-mind)/3, alpha=0.5, label="simulation")
- plt.title("{0} - {1} @ {2} rolls".format(mind, maxd, numrolls))
- plt.xlabel("Value")
- plt.ylabel("Frequency")
- plt.legend(loc="upper right")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement