Created
August 16, 2019 22:37
-
-
Save bnorthan/00d922d4dedb8620b921633a3eb6d14c to your computer and use it in GitHub Desktop.
How many people in the room have the same birthday
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i=1:365 | |
% let's simulate 1000 times | |
for j=1:1000 | |
% make a vector of random numbers (1 to 365) i times | |
test=randi(365,[1 i]); | |
% test if there is a duplicate | |
dupbirthday(i,j)=~(length(test) == length(unique(test))); | |
end | |
end | |
for i=1:365 | |
% calculate percentage of times there is a duplicate birthday in 1000 trials | |
perdupbirthday(i)=sum(dupbirthday(i,:))/1000; | |
end | |
% plot it | |
plot(perdupbirthday) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment