Is there a simulation for the Birthday Paradox?

530 Views Asked by At

Is there a simulation for the Birthday Paradox problem? Something that uses data from Facebook would be ideal.

2

There are 2 best solutions below

0
On

Here is a pythonic answer to your request.

from sys import argv
import random
def hasAMatch(sample):
    q = set(sample)
    return len(q) < len(sample)
n = int(argv[1])
repetitions = int(argv[2])
days = range(365)
matches = 0
for k in range(repetitions):
    sample = []
    for k in range(n):
        sample.append(random.choice(days))
    matches += int(hasAMatch(sample))
print "In a simulation with %d repetitions, group of randomly chosen" % repetitions
print "sample of %s people, we had a matching birthday %s%% of the time." % (n, float(matches)*100/repetitions)
2
On

As someone in the comments mentioned, there are some of us weirdos that are not on Facebook. For all of the non-Facebook freaks, this one is for you(me):

There is data: http://www.panix.com/~murphy/bday.html purporting to show that birthdates are not uniformly-distributed. Specifically, they show data for n=480,040 birthdates that failed a $\chi^2$ =$\frac{(observed-expected)^2}{expected}$, where the expected number is $\frac{480,040}{365.25}$ , at a 95% level of confidence

If you have acces to JSTOR, this link should help describe how to address the birthday problem under more realistic assumptions on the distribution of birthdates : http://www.jstor.org/pss/2685309