From 210cf4418cb5d8d52a85ceef0cf108eda68c6366 Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:18:57 +0000 Subject: [PATCH] started birthday paradox --- birthdayparadox.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 birthdayparadox.py diff --git a/birthdayparadox.py b/birthdayparadox.py new file mode 100644 index 0000000..5ef7412 --- /dev/null +++ b/birthdayparadox.py @@ -0,0 +1,23 @@ +""" Birthday Paradox Simulation, by Al Sweigart al@inventwithpython.com +Explore the surprising possibilities of the "Birthday Paradox". +More info at https://en.wikipedia.org/wiki/Birthday_problem +View this code at https://nostarch.com/big-book-small-python-projects +Tags: short, math, simulation""" + +import datetime, random + +def getBirthdays(numberOfBirthdays): + """Returns a list of number random date objects for birthdays.""" + birthdays = [] + for i in range(numberOfBirthdays): + # The year is unimportant for our simulation, as long as all + # birthdays have the same year. + startOfYear = datetime.date(2001, 1, 1) + + # Get a random day into the year: + randomNumberOfDays = datetime.timedelta(random.randint(0, 364)) + birthday = startOfYear + randomNumberOfDays + birthdays.append(birthday) + return birthdays + + \ No newline at end of file