Problem. With people and equally likely birthdays, what is the probability that two share a birthday? 23 people already give more than .
double birthdayCollision(int k, int d) { double p = 1; for (int i = 0; i < k; i++) p *= (double)(d - i) / d; return 1 - p; }
int birthdayHalf(int d) { int k = 0; while (birthdayCollision(k, d) < 0.5) k++; return k; }| Consequence | Value |
|---|---|
| people for 50% | (23 for 365) |
| random 64-bit hashes of strings | collision likely once |
| hashing mod a prime with items | collision probability : use two moduli or 64 bits (Hashing) |
| Pollard’s rho | finds a factor after steps, by the same bound |
Proof: the product formula and the approximation
The -th person avoids the earlier birthdays with probability , independently given the earlier ones being distinct, so all are distinct with probability . Using , the product is at most , which is also the leading-order value; it drops below when . The code finds for .