Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: MAT 1630
Views: 220
Kernel: Python 3 (Anaconda 2019)

Die Roll Probability

Suppose that NN people (with 2N152\leq N\leq 15) each roll a 20-sided die. The goal of this activity is to determine the probability that at least two people obtain the same die roll via simulations.

For a fixed NN, we will run the following procedure 10,000 times:

  1. Select a random integer from 1 to 20, NN times.

  2. Determine if at least one integer appears in the random sample more than once.

  3. Return a 1 if the previous step is true and 0 otherwise.

We can then average our result to get an approximate value for the desired probability.

import numpy as np
def dieRoll(N): rolls = np.random.randint(1,21,size=N) for i in range(N-1): if rolls[i] in rolls[i+1:]: return 1 return 0
def sim(N): print("The probability that at least two people out of " + str(N) + " roll the same number on a 20-sided die is approximately: " + str(sum([dieRoll(N) for i in range(10000)])/10000))
for i in range(2,16): sim(i)
The probability that at least two people out of 2 roll the same number on a 20-sided die is approximately: 0.0512 The probability that at least two people out of 3 roll the same number on a 20-sided die is approximately: 0.1465 The probability that at least two people out of 4 roll the same number on a 20-sided die is approximately: 0.2687 The probability that at least two people out of 5 roll the same number on a 20-sided die is approximately: 0.4192 The probability that at least two people out of 6 roll the same number on a 20-sided die is approximately: 0.5594 The probability that at least two people out of 7 roll the same number on a 20-sided die is approximately: 0.6943 The probability that at least two people out of 8 roll the same number on a 20-sided die is approximately: 0.804 The probability that at least two people out of 9 roll the same number on a 20-sided die is approximately: 0.8787 The probability that at least two people out of 10 roll the same number on a 20-sided die is approximately: 0.9367 The probability that at least two people out of 11 roll the same number on a 20-sided die is approximately: 0.9692 The probability that at least two people out of 12 roll the same number on a 20-sided die is approximately: 0.9848 The probability that at least two people out of 13 roll the same number on a 20-sided die is approximately: 0.9946 The probability that at least two people out of 14 roll the same number on a 20-sided die is approximately: 0.9984 The probability that at least two people out of 15 roll the same number on a 20-sided die is approximately: 0.9989