Considering an event where you roll multiple dice and take the max value observed. I am writing a function that will randomly simulate this event multiple times and return the maximum value obtained in each trial.
Not really sure what I have done is correct. Also, I would like to plot a histogram of resulting max values but plt.hist dosen't seem right. Any insights will be appreciated
import random
def multipleRolls(numberoftrials, numberofdice):
trial_list=[]
min = 1
max = 6
for i in range (1,numberoftrials+1):
m=0
for j in range(1,numberofdice+1):
k = random.randint(min, max)
if m<k:
m=k
trial_list.append(m)
plt.hist(trial_list)
plt.show()
print(trial_list)
multipleRolls(3,5)
Aucun commentaire:
Enregistrer un commentaire