Logo

Back to Blog

Generalized Birthday Problem

Written by: Charles Flock
6/19/2025 1:21 PM

In November 2008, we wrote about the birthday paradox. In this article.

Sooner or later in most high school statistics courses students are presented with following problem; “How many people need to be in a room for there to be a 50% chance of 2 people having the same birthday?” This problem, known as the birthday paradox (which we wrote about in 2011), serves as an introduction into basic combinatorics and is appealing because the solution is surprising.


Here’s a very easy way to calculate the answer in SQL, using the XLeratorDB PERMUT function.

DECLARE @x as int = 2
DECLARE @p as float = 1-wct.PERMUT(365,@x)*wct.POWER(365,-@x)
   
WHILE @p < 0.5
    BEGIN
        SET @x = @x + 1
        SET @p = 1-wct.PERMUT(365,@x)*wct.POWER(365,-@x)
    END
 
SELECT @x as N

This produces the following result.

          N
-----------
         23

3 people having the same birthday


Using McKinney’s formulation, the probability of three people having the same birthday in a room of size n can be defined as:


bb.jpg


The term P(n;n1,n2 ) is the probability that no birthday is shared k or more times in a specific arrangement of n people. The real challenge, then, is coming up with all the possible arrangements of n people, something that is actually quite simple to do in SQL. Let’s look at an example.


In a room with 10 people, we are looking for all the combinations of n1 + n2 = 10, where n1 is the number of non-repeated items and n2 is the number or pairs. With such a small number, it’s easy to see all the possible arrangements.

See results in your own environment

Try it risk-free for 15 days

No sales calls. No credit card required. Install the full version of XLeratorDB and test it with your actual data and workloads. Within minutes, you'll be running advanced calculations that would typically require expensive third-party tools or complex custom development.

Performance benchmarks

Process millions of rows and compare speeds to your current methods

Accuracy validation

Verify calculations against your existing systems and trusted sources

Integration testing

Confirm compatibility with your SQL Server environment and workflows

Team evaluation

Let your analysts and developers explore the function library