CoCalc Public FilesProjects / S21 / dieroll_Proj8 / Project 8.ipynb
Author: C Y
Views : 98
Compute Environment: Ubuntu 20.04 (Default)

# The purpose of this project is to create simulations of 20 sided die and to estimate the odds of two or more people rolling out the same number if 2-15 people were to roll it.

In [1]:
import numpy as np

In [2]:
def repeating_numbers():
n=np.random.randint(2,16,size=1)           # making "n" between 2-15,since the number of people rolling the die is 2-15
die_roll =np.random.randint(1,21,size=n)     # number on die with n amount of times
unique_values=[]
for value in die_roll:
if value not in unique_values:
unique_values.append(value)
if len(unique_values) ==n:                  # if total number is less than n then it means that at least 2 people rolled the same number
return 0                                # if n is exactly n than it mean each people rolled a different number
else:
return 1


In [3]:
sum([repeating_numbers() for i in range(1000)])/1000 # calculating the probabilty by adding up all the ones in the trials and divide it by the                                                        total amount of trials (in this case 1000 trials)

0.694

# base on the experiment (with 1000 trials), the probabilty of 2 or more people rolling the same number, with 2-15 people playing is 0.694

In [ ]: