Simulates birthday problem with monte carlo simulation.
More informations about the problem here.
compile: make
run: ./birthday.out
if you compile without makefile put the -O3
flags, it drastically reduces time of esecutions!
ExpeimentI generates n=500000
groups of people with random birthday during a year, then checks how may groups have got almost two people born in the same day.
ExperimentII still call people with random birthday until two have the same, it does it n=500000
times then tells the average number of people needed.
You can check that for about 23 people the probability of find two people with same birthday is near 50%!
this program uses a special yearrand()
function, which returns a random integer based on real data provided by italian statistic institute.
source (date of born in Italy in 2014): http://demo.istat.it/altridati/IscrittiNascita/
I did this (you can do the same):
- got data from here
- fit the data with a polinomial (grade 3) function
- generate random number between 1 and 365 based on that distribution
The MIT License (MIT) 2016 fvalle1
See LICENSE