Birthday Paradox

In a room with 23 people, what is the probability that there is at least one pair of people with the same birthday? The answer is about 50%! It is a little counter intuitive but it is a mathematical fact, which you can try to prove.

Now let’s simulate this process with Python and Turtle. Draw a grid of 365 numbers. At each iteration, randomly generate 23 numbers ranging from 1 to 365 and fill the corresponding grid with blue color. When a number is repeating, fill the grid the red color, meaning two people have the same birthday. Count the number of birthday matches and display the ratio of birth matches and the total number of iterations. Is it about 50%?

Birthday Paradox with Python Turtle

Related Post