# -------------------------------------- # Simulate rolling 2 dice and plot the results. # -------------------------------------- import numpy as np import matplotlib.pyplot as plt # -------------------------------------- def generateRolls(howMany): result = np.ndarray(howMany, dtype=int) for roll in range(howMany): result[roll] = np.random.randint(1, 7) + np.random.randint(1, 7) return result # -------------------------------------- def main(): rolls = generateRolls(10000) plt.hist(rolls, bins=np.arange(2, 14), facecolor='g', align='left') # generate histogram plt.xticks(np.arange(2, 13)) plt.xlim(1.5, 12.5) plt.xlabel('Value') plt.ylabel('Occurrences') plt.title('Histogram of Dice Rolls') plt.grid(True) plt.show() # -------------------------------------- if __name__ == "__main__": main()