import numpy as np import matplotlib.pyplot as plt # Antall stokastiske forsøk: n = 10000 # Innstillinger for choice(): sample_space = np.linspace(1, 365, 365) antall = np.linspace(2, 50, 49) prosent = np.zeros(49) # For-løkke med iterasjon for hvert antall personer (j): for j in range(2, 51, 1): gunstige = 0 for k in range (0, n): bursdag = np.random.choice(sample_space, j) # Rangerer bursdager i stigende rekkefølge: bursdag.sort() for i in range(0, len(bursdag) - 1, 1): if (bursdag[i] - bursdag[i+1] == 0): gunstige = gunstige + 1 break prosent[j-2] = gunstige/n # print('Antall personer (j) =', j) # print('Hyppighet for lik bursdag:', # f'{gunstige/n :.4f}') plt.plot(antall, prosent, 'bo') plt.grid() plt.xlabel('Antall personer') plt.ylabel('Estimat av sannsynlighet for samme bursdag') # plt.savefig('plott_samme_bursdag.pdf') plt.show()