Advertisement
doomium

Untitled

Mar 4th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from random import uniform as r
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4.  
  5. plt.figure(1)
  6.  
  7. for numrolls in range(1, 10):
  8.     plt.subplot(1, 9, numrolls)
  9.     mind = 50
  10.     maxd = 250
  11.     samplesize = 1000000
  12.  
  13.     rolls = []
  14.  
  15.     for i in range(samplesize):
  16.         roll = []
  17.         for ii in range(numrolls):
  18.             roll.append(r(mind, maxd))
  19.         rolls.append(np.average(roll))
  20.  
  21.     normal = np.random.normal(loc=(mind+maxd)/2, scale=(maxd-mind)/7, size=samplesize)
  22.  
  23.     plt.hist(normal, bins=(maxd-mind)/3, alpha=0.5, label="normal")
  24.     plt.hist(rolls, bins=(maxd-mind)/3, alpha=0.5, label="simulation")
  25.     plt.title("{0} - {1} @ {2} rolls".format(mind, maxd, numrolls))
  26.     plt.xlabel("Value")
  27.     plt.ylabel("Frequency")
  28.     plt.legend(loc="upper right")
  29. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement