Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 143
Image: ubuntu2004
Kernel: Python 3 (system-wide)

Introduction :

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.

import numpy as np
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
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