# Is there a simulation for the Birthday Paradox?

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

-
Like this? – J. M. Jul 30 '11 at 21:49
@JM. That looks like it almost completely answers the question. You might as well put it as an answer. – Willie Wong Jul 31 '11 at 0:15
@Willie: Except that it is completely inaccessible for people that (gasp!) don't use Facebook. :) – cardinal Jul 31 '11 at 1:13
@cardinal: ...and I'm a member of that group. :D (P.S. Dear Google, if you're reading this, thanks bunches for helping me answer at least half this site's questions. Hugs, J.M.) – J. M. Jul 31 '11 at 2:49
@J.M., As am I, so how did you view it? As for Google, I'm pretty sure it's reading this. :) – cardinal Jul 31 '11 at 4:02

## 2 Answers

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

-
Interesting! I suspect that U.S. data for any recent single year would show even greater non-uniformity, because of the high Caesarian rate, and the fact that doctors prefer to golf on weekends. – André Nicolas Jul 31 '11 at 5:32
I haven't been able to find any more recent data, tho I suspect you're right. I may have to open a (fake) account in Facebook to check it out. It would be interesting to find specific data on those two factors, too, though. – gary Jul 31 '11 at 6:00

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)

-