Final answer:
The 'birthday paradox' explores the probability of two people sharing the same birthday in a group. The Python function randomNumbers generates random numbers to simulate birthdays and identifies when duplicates occur. Simulations show that with just 23 people, there is over a 50% chance of a shared birthday.
Step-by-step explanation:
Exploring the Birthday Paradox with Python
To explore the birthday paradox, we will write a Python function called randomNumbers that takes two parameters: upTo (the range of days in a year to simulate birthdays) and num (the number of random 'people' or 'birthdays' to simulate). The function generates random numbers between 1 and upTo, and each number represents a person's birthday. The numbers are added to a set to ensure uniqueness (since sets cannot have duplicate elements) and finally, the function returns the number of unique birthdays generated.
When num exceeds 365, we're certain to have at least one duplicate birthday. But to find the smallest number of people needed in order to have a greater than 50% chance of a shared birthday, we will need to perform simulations with different values of num. Empirical tests suggest the number is surprisingly low, around 23 people.
Here is the Python function to run the simulation:
import random
def randomNumbers(upTo, num):
birthdays = set()
for _ in range(num):
birthdays.add(random.randint(1, upTo))
return len(birthdays)
Real-world simulations can then be run using various values for num. As the value of num approaches 23, we will begin to see that the number of unique birthdays is less than num, indicating a collision where at least two individuals share the same birthday.