Birthday Paradox

Description

"In probability theory, the birthday problem or birthday paradox concerns the probability that, in a set of n randomly chosen people, some pair of them will have the same birthday. By the pigeonhole principle, the probability reaches 100% when the number of people reaches 367 (since there are only 366 possible birthdays, including February 29). However, 99.9% probability is reached with just 70 people, and 50% probability with 23 people. These conclusions are based on the assumption that each day of the year (excluding February 29) is equally probable for a birthday."

Source
Test it

This is a python program that takes in the number of people and how many iterations to run. Random birthdays are generated for each person and the number of matches is counted. If multiple iterations were chosen, this process is repeated. The number of iterations with at least one match is divided by the total number of iterations to get the probablity. If the verbose option is selected, each trial will also display the number of people on each birthday. (This can slow the program down)

Probability Calculated Experimentally

The graph and data below show what the probability is for 0 - 99 people. For each number of people, 10 trials of 10,000 iterations were run and averaged. This data was then plotted as number of people vs probability of a match.

Num people Trial 1 Trial 2 Trial 3 Trial 4 Trial 5 Trial 6 Trial 7 Trial 8 Trial 9 Trial 10 Average
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0
2 0.3 0.2 0.2 0.24 0.29 0.22 0.33 0.25 0.25 0.24 0.252
3 0.99 0.91 1.05 0.76 0.9 1.02 0.95 0.62 0.82 0.84 0.886
4 1.53 1.73 1.66 1.68 1.66 1.73 1.75 1.87 1.51 1.74 1.686
5 2.86 2.83 2.65 2.55 2.58 2.74 2.62 2.82 2.87 2.5 2.702
6 3.9 3.77 4.15 3.98 4.09 3.76 4.5 4.12 3.96 3.71 3.994
7 5.77 5.38 5.28 5.56 5.52 5.71 5.53 5.54 5.19 5.61 5.509
8 7.34 6.98 7.52 7.32 7.68 7.39 7.52 7.25 7.45 7.79 7.424
9 8.9 9.43 9.57 9.54 9.5 9.64 9.59 9.07 9.84 9.45 9.453
10 12.06 11.31 11.96 11.59 12.16 11.77 12.04 11.27 11.88 12.26 11.83
11 13.8 14.54 14.04 14.03 14.25 13.8 14.12 13.9 14.12 14.1 14.07
12 16.84 16.91 17.06 17.13 16.44 17 17.1 16.6 16.66 16.97 16.871
13 19 19.63 19.71 20.47 19.16 19.76 19.73 19.68 19.73 19.59 19.646
14 22.18 22.15 22.11 22.47 22.97 22.39 21.24 21.56 22.67 22.23 22.197
15 25.59 25.67 24.95 25.18 25.1 25.5 25.67 25.04 26.2 25.68 25.458
16 28.41 28.08 28.72 28.1 28.48 28.38 28.16 27.5 28.33 27.86 28.202
17 30.33 31.87 31.41 31.87 31.58 30.98 31.8 31 31.48 31.46 31.378
18 34.6 34.67 35.07 34.37 35.82 35.25 35.45 34.27 34.34 34.81 34.865
19 38.6 38.56 37.72 37.7 37.77 37.82 38.06 38.11 37.74 37.27 37.935
20 40.84 41.47 41.12 40.86 40.38 40.51 40.52 41.42 40.56 41.29 40.897
21 44.73 44.4 43.49 44.51 45.56 44.9 42.91 43.86 44.16 43.97 44.249
22 47.73 47.39 47.19 47.51 47.93 47.9 48.4 48.01 47.42 46.83 47.631
23 50.25 50.63 51.25 50.81 51.36 50.9 50.73 50.42 50.95 50.42 50.772
24 53.84 53.62 54.4 53.36 54.12 54.03 53.54 54.31 53.61 53.87 53.87
25 56.46 56.51 56.74 57.07 56.62 57.13 56.45 56.59 56.27 56.65 56.649
26 59.59 58.9 59.91 59.77 59.16 59.61 60.11 59.39 59.37 59.59 59.54
27 63.06 63.44 62.61 62.81 63.11 62.78 63.21 62.12 62.3 62.72 62.816
28 65.39 64.97 65.51 65.58 65.61 65.96 65.28 65.45 66.24 64.77 65.476
29 67.45 67.95 67.67 68 67.54 68 68.79 67.42 67.82 68.46 67.91
30 70.85 70.31 70.45 71.81 70.6 71.09 70.1 69.71 70.38 70.89 70.619
31 72.63 72.24 73.69 73.54 72.72 72.82 72.18 73.78 72.74 73.37 72.971
32 74.99 74.57 74.95 75.31 75.7 74.6 74.73 74.77 74.77 76.32 75.071
33 76.86 77.08 78.52 77.55 77.77 77.58 77.6 77.89 77.89 77.6 77.634
34 79.95 79.5 80.04 79.7 79.72 79.24 80.24 79.89 79.86 78.98 79.712
35 81.25 82.11 81.27 82.17 80.94 81 81.31 81.52 81.48 81.9 81.495
36 82.44 82.36 84.12 83.57 82.66 82.85 83.98 84 82.56 82.62 83.116
37 84.73 84.94 84.52 84.91 85.12 84.84 84.73 85.12 84.93 84.47 84.831
38 86.53 85.6 86.48 86.2 85.79 86.86 86 86.12 86.41 86.42 86.241
39 88 87.38 87.49 87.71 87.84 87.64 87.1 87.69 87.92 87.7 87.647
40 89.56 89.27 89.06 88.94 89.29 89.45 88.66 89.02 89.03 89.16 89.144
41 90.3 90.04 89.34 90.69 90.1 90.27 90 90.37 90.48 90.1 90.169
42 91.46 91.98 91.64 91.21 91.78 90.95 91.36 91.54 91.24 91.22 91.438
43 92.17 92.3 92.65 92.51 92.3 92.28 92.36 92.17 92.4 92.41 92.355
44 93.53 93.44 93.21 93.11 93.47 93.6 93.24 93.02 92.79 93.46 93.287
45 94.07 94.01 93.94 94.09 94.45 94.18 93.95 94.14 93.84 94.15 94.082
46 95.28 94.6 94.81 95.05 94.95 95.16 94.28 95.29 94.46 94.8 94.868
47 95.3 95.31 95.78 95.72 95.27 95.95 95.76 95.76 95.57 95.52 95.594
48 95.95 95.98 96.05 95.84 96.34 96.02 95.89 96.13 95.9 95.77 95.987
49 96.4 96.4 96.54 96.58 96.66 96.8 96.4 96.69 96.39 96.71 96.557
50 96.94 97.19 97.05 97.05 97.18 97.03 96.99 97.05 97.14 96.61 97.023
51 97.5 97.67 97.43 97.57 97.26 97.08 97.3 97.12 97.39 97.56 97.388
52 97.74 97.87 98 97.88 97.72 97.85 97.82 97.65 97.77 97.84 97.814
53 98.07 98.12 97.97 97.92 97.99 98.26 98.27 98.09 97.94 97.95 98.058
54 98.46 98.21 98.34 98.48 98.52 98.29 98.37 98.18 98.48 98.48 98.381
55 98.77 98.46 98.63 98.83 98.49 98.5 98.53 98.55 98.84 98.66 98.626
56 98.79 98.96 98.93 98.75 98.9 98.9 98.7 98.92 99.08 98.98 98.891
57 99.22 99.04 99 98.89 99.04 99.04 99.12 99.02 99.08 98.96 99.041
58 99.21 99.17 99.15 99.14 99.19 99.24 99.25 99.09 98.98 99.01 99.143
59 99.31 99.27 99.4 99.29 99.21 99.37 99.39 99.33 99.29 99.39 99.325
60 99.39 99.37 99.33 99.38 99.44 99.33 99.39 99.42 99.42 99.4 99.387
61 99.49 99.51 99.52 99.6 99.52 99.6 99.6 99.46 99.51 99.45 99.526
62 99.71 99.49 99.6 99.68 99.66 99.55 99.64 99.58 99.58 99.64 99.613
63 99.7 99.62 99.72 99.58 99.63 99.59 99.63 99.6 99.67 99.64 99.638
64 99.71 99.71 99.59 99.77 99.63 99.63 99.78 99.72 99.78 99.85 99.717
65 99.78 99.79 99.74 99.78 99.79 99.89 99.74 99.77 99.76 99.78 99.782
66 99.89 99.82 99.78 99.85 99.74 99.78 99.84 99.79 99.92 99.86 99.827
67 99.81 99.87 99.72 99.87 99.87 99.9 99.84 99.85 99.91 99.81 99.845
68 99.85 99.89 99.85 99.88 99.97 99.92 99.89 99.87 99.92 99.93 99.897
69 99.92 99.88 99.87 99.88 99.9 99.89 99.87 99.9 99.87 99.91 99.889
70 99.94 99.94 99.9 99.9 99.91 99.98 99.96 99.87 99.93 99.87 99.92
71 99.96 99.96 99.89 99.9 99.97 99.91 99.9 99.94 100 99.95 99.938
72 99.96 99.97 99.96 99.95 99.91 99.96 99.91 99.95 99.93 99.95 99.945
73 99.92 99.98 99.98 99.96 99.98 100 99.92 99.96 99.96 99.91 99.957
74 99.98 99.96 99.97 99.96 99.96 99.98 99.97 99.95 99.94 99.98 99.965
75 99.97 99.99 99.94 99.97 99.93 99.99 99.96 99.96 99.96 99.96 99.963
76 99.96 100 99.98 99.95 99.98 99.98 99.98 99.96 99.97 99.97 99.973
77 99.99 99.99 99.98 100 100 99.97 99.97 99.97 99.97 99.99 99.983
78 99.97 99.98 99.98 99.98 100 99.99 99.99 100 99.96 100 99.985
79 100 99.98 100 99.98 99.99 99.99 99.99 100 100 99.99 99.992
80 99.98 99.99 99.97 100 99.99 99.99 99.99 99.99 99.99 99.99 99.988
81 100 100 99.98 100 100 100 100 100 99.99 100 99.997
82 100 100 100 99.99 99.99 100 99.99 99.98 99.99 99.99 99.993
83 100 99.99 100 100 100 100 100 100 100 100 99.999
84 100 99.98 100 100 100 100 100 100 100 100 99.998
85 99.99 100 100 100 100 99.97 100 100 100 100 99.996
86 100 100 99.99 100 99.99 100 100 100 100 100 99.998
87 100 100 100 100 100 100 99.99 100 100 100 99.999
88 100 100 100 100 100 99.99 100 100 100 100 99.999
89 100 100 100 100 100 100 100 100 100 100 100
90 100 100 100 99.99 99.99 100 100 100 100 100 99.998
91 100 100 100 100 100 100 100 100 100 100 100
92 100 99.99 100 100 100 100 100 100 100 100 99.999
93 100 100 100 100 100 100 100 99.99 100 100 99.999
94 100 100 100 100 100 100 99.99 100 100 100 99.999
95 100 100 100 100 100 100 100 100 100 100 100
96 100 100 100 100 100 100 100 100 100 100 100
97 100 100 100 100 100 100 100 100 100 100 100
98 100 100 100 100 100 100 100 100 100 100 100
99 100 100 100 100 100 100 100 100 100 100 100
Code