Advertisement
SepandMeenu

Probability distribution of sum of three dice rolls

Sep 20th, 2020 (edited)
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. # probability distribution of sum of three dice rolls
  2.  
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. N = 6
  7. rng = range(1, N+1)  # range of dice numbers
  8. MAX = 3 * N
  9.  
  10. counts = []
  11. for total in range(MAX + 4):
  12.     n = 0
  13.     for i in rng:
  14.         for j in rng:
  15.             k = total - (i + j)
  16.             if 0 < k <= N:
  17.                 n += 1
  18.     counts.append((total, n))
  19.  
  20. # normalized probability distribution
  21. dist = np.array(counts, dtype=float)
  22. dist[:, 1] /= np.sum(dist[:, 1])
  23.  
  24. plt.plot(dist[:, 0], dist[:, 1], '+', lw=0, )
  25. plt.show()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement