Skip to content

Instantly share code, notes, and snippets.

@bnorthan
Created August 16, 2019 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnorthan/00d922d4dedb8620b921633a3eb6d14c to your computer and use it in GitHub Desktop.
Save bnorthan/00d922d4dedb8620b921633a3eb6d14c to your computer and use it in GitHub Desktop.
How many people in the room have the same birthday
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