Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # probability distribution of sum of three dice rolls
- import numpy as np
- import matplotlib.pyplot as plt
- N = 6
- rng = range(1, N+1) # range of dice numbers
- MAX = 3 * N
- counts = []
- for total in range(MAX + 4):
- n = 0
- for i in rng:
- for j in rng:
- k = total - (i + j)
- if 0 < k <= N:
- n += 1
- counts.append((total, n))
- # normalized probability distribution
- dist = np.array(counts, dtype=float)
- dist[:, 1] /= np.sum(dist[:, 1])
- plt.plot(dist[:, 0], dist[:, 1], '+', lw=0, )
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement