# How to calculate probably number of tries to guess someone's birthday in a room with N people?

A and B are sequences of random numbers where each number is an independantly random number from 1 to 365.

i and j are sequence positions in a and b

What's the probability that the set A(1..i) intersect B(1..j) is not empty?

Update: To help frame this as a real world problem, let's say you had a company of 50 people and made the entry code to the building everyone's birthday - then someone found out this was the case - how many guesses would it statistically take to gain entry?

Note: I'm not planning a heist.

-

## 2 Answers

First, consider the count $D$ of distinct numbers in the sequence $A(1..i)$. Given that $D = d$, the probability that $B(1..j)$ does not intersect $A(1..i)$ is equal to: $$P(D = d) = \left(\frac{365-d}{365}\right)^j$$

so the sought probability would be $1 - \left(\frac{365-d}{365}\right)^j$.

If however $D$ is unknown (i.e. variable), a more complicated expression (involving the probability for $D$ assuming certain values) comes in to play. If you are interested, I can write it up for you, but it will probably be a nasty expression.

-

You have $ij$ pairs that might match, each with probability $\frac 1{365}$ (assuming the usual rules). Are they selected independently? Do you know that all the numbers in sequence A are distinct? These will change the answer.

-
I updated my question to make it more concrete/specific (hopefully) – Aaron Anodide Oct 9 '12 at 19:12