import random as rnd import matplotlib.pyplot as plt import numpy as np def dice(n=1, d=6): eyes = 0 sides = range(1, d + 1) for roll in range(n): eyes += rnd.choice(sides) return eyes rnd.seed(rnd.random()) rolls = 1000 d_dice = 6 n_dices = 6 total_sum = 0 results = [0 for i in range(0, d_dice * n_dices + 1 + n_dices)] for a in range(rolls): val = dice(n_dices, d_dice) total_sum += val results[val] += 1 avg = total_sum / rolls fig, ax = plt.subplots() ax.plot( np.array(range(0, d_dice * n_dices + 1 + n_dices)), np.array(results), color="red" ) ax.plot( np.array(range(0, d_dice * n_dices + 1 + n_dices)), np.array([avg for i in range(0, d_dice * n_dices + 1 + n_dices)]), color="blue" ) ax.set_xlabel("Summierte Augenzahl") ax.set_ylabel("Vorkommen") ax.set_title("Verteilung") plt.show() for b in range(0, d_dice * n_dices + 1 + n_dices): print(f"Summe: {b}, Vorkommen: {results[b]}")