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