/* Birthday matching problem: compute a probability through simulation */ #include #include /* for srand48(), drand48() */ int n = 50; /* number of peoples */ int n_trials = 1000000; int B[365]; int main (int argc, char *argv[] ) { int i,j; int d; int match = 0; int seed = 20110615; srand48(seed); for (j=0; j -1 ){ // printf("already exists d=%d, B[d]=%d, i=%d\n", d, B[d], i); match++; break; } else{ B[d] = i; } } } printf("prob = %.8lf \n", (double)match/(double)n_trials); return 0; }