I saw this same problem a while back myself. If I recall correctly, the answer was 50 before the odds would be better than 50-50 of 2 people in the room having the same birthday. The 1st person as 1/365th of a chance of being on a particular day, the odds the 2nd person having one other than the first is 364/365ths, the 3rd having a different birthday 363/365ths, and so forth.

As to modeling this situation, you would have to keep track of the day (potentially an array 0..364), and add people until you hit the same day for two of them. Then, you would need to simulate it multiple times (such as your $TRIALS=1024) to get an estimate.

Enjoy. (The code below might give you a starting place, but may require you to run considerably longer to get a better estimate.)

#!/usr/bin/perl -w use strict; use warnings; srand(); my $maxday = 365; my $TRIALS = 1024000; my $average = 0; my $sum = 0; my $tenpercent = $TRIALS / 10; for (my $count = 0; $count < $TRIALS; $count++) { $sum += &test_bdays($maxday); if (($count) and (!($count % $tenpercent))) { $average = ($sum * 1.0) / $count; print("After $count trials, ", "the average number of people in the room was $average\n"); } } $average = ($sum * 1.0) / $TRIALS; print("After $TRIALS trials, ", " the average number of people in the room was $average\n"); sub test_bdays { my ($mday) = @_; my @days = (); my $d = $mday; my $people = 0; while ($d) { $days[$d] = 0; $d--; } my $flag = 0; while (!($flag)) { $people++; my $index = int(rand() * $mday); $days[$index]++; $flag = ($days[$index] > 1); } return($people); }
Update:

thraxil is correct-I bow both to his math skill and to his remembering the correct answer. An article at http://www.people.virginia.edu/~rjh9u/birthday.html discusses it more. It had made me wonder when the simulations I ran with the script above seemed to fall within the range between 20 and 25....


In reply to Re: Birthday Chances by atcroft
in thread Birthday Chances by YuckFoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.