Enter the number of people in a group and this program will calculate the chance that
two of them have the same birthday (not counting the year.)

**Two things are cool about this program:**

1. With only a small group of people (say 23), there is a pretty good chance (50%) that at least two of those people have the same birthday. This might seem counter-intuitive given the number of days in a year, which is 366 counting the leap day.

2. It takes a very large number of people (around 850) to have a greater then 90% chance that someone has the same birthday as you. This may also seem counter-intuitive given that there are only 366 possible different birthdays, counting the leap day.

**Notes on these results:**

Theoretically, there must be 367 people in a group to insure a 100% probability that two of them have the same birthday. The reason is this: It is theoretically possible to have a group of 366 people all of whom have different birthdays because that's how many days there are in a year, counting the leap day. However, if another person was added to the group, there would be 367 people and therefore more people than there are possible birthdays and hence, it is absolutely certain that at least two of them would have the same birthday. However, because of the limitations of the programming language used, if more than 153 people are selected, the chance of two of them having the same birthday is so close to 100% that this program rounds off the answer to 100%. Even though this number is not really reached until there are 367 people in the group.

Contrast this with the very unlikely possibility of selecting a random group of 850 people, all of whom have birthdays different than yours. Theoretically possible, although with a very small probability. Clearly it is possible to chose any number of people who don't have the same birthday day as you. Therefore, in any group of randomly selected people, theoretically, there will never be a 100% chance that someone has the same birthday as you. However, again because of the limitations of software used for this program, if the number of people chosen is larger than about 13680, the program rounds off the answer to 100%.

**Explanation of the calculations:**

The first calculation is done in the following way: The chance that say, five randomly chosen people do not have the same birthday is

(366*365*364*363*362)/(366*366*366*366*366).

The numerator represents the number of possible dates where no one has the same birthday, the denominator represents the total number of possible birthdates for five people. Call the probability that none of the five has the same birthday "p." Then the opposite probability, that at least two of them have the same birthday, is 1-p. This is what is printed above as the first result (and is called result1 in the program code.)

The second calculation is done as follows: The chance that say, again five randomly chosen people do not have a given birthday, say your birthday, is

(365*365*365*365*365)/(366*366*366*366*366)

Here the numerator represents the number of different days in the year besides your birthday, on which each of those five people could have their birthday. The denominator represents the number of possible birthdays for five people. As before, this probability we will call p, and as before, the opposite probability, that at least one person has the same birthday as you, is therefore 1-p. (This is called result2 in the program code.)

* *

*=====================================================================*

** Source Code:** The program running above is in Java.
Here is the code...

import java.awt.*;

public class bday extends java.applet.Applet {

Label numLable = new Label("Input
number of people:");

TextField num
= new TextField(5);

Button submit
= new Button("Submit");

String
input = "";

TextArea output = new
TextArea(input,10,75);

double result1 = 0D;
//stores chance at least 2 have same
bday

double result2 = 0D;
//stores chance at least 1 other has specific
bday

boolean moreThanOnePerson =
false;

public void init() {

add(numLable);

add(num);

add(submit);

add(output);

output.setEditable(false);

}

public boolean action(Event
evt, Object arg) {

if (evt.target instanceof Button)
{

String label =
(String)arg;

if (label.equals("Submit"))
{

input =
num.getText();

num.setText("");

doCalculation();

if (moreThanOnePerson)
printResults();

}

return
true;

}
else

return false;

}

public void
doCalculation() {

int i,
num_people;

double p,r,v;

r = 0D; v = 1D;

num_people = Integer.parseInt(input);

if (num_people < 2)
{

output.appendText("There must be more than one
person.\n\n");

moreThanOnePerson =
false;

}

else
{

moreThanOnePerson =
true;

for (i=366; i>=367-num_people; i--) {

r =
(double)i/366;

v = v *
r;

}

result1 = 100*(1-v);

r = (double)365/366; v = 1D;

for (i=1; i <= num_people; i++)
{

v = v *
r;

}

result2 = 100*(1-v);

}

}

public void
printResults()
{

output.appendText("Chance that at least two people have the same birthday =
"+result1+"%\n");

output.appendText("Chance that at least one other person has the same birthday
as you =
"+result2+"%\n");

output.appendText("\n");

}

public void start() {

num.requestFocus();

}

}