function[prob]=birthday(trialmax);

%Birthday.m will calculate the probability that 2 persons share the same
%birthday by running through trialmax trials for a given group size

%Loop through different amounts of persons
for a=2:70
    
    %for given amount of people, loop over addition of each person, once
    %match occurs, exit loop
    totalcount(a)=0;
    xaxis(a)=a;
    
    %run through trialmax trials for a persons
    for trials=1: trialmax

    %Introduce new people     
        for i=1:a
             match=0;
             birthday(i)=ceil(365*rand);    %Assign a random birthday to the ith person
             j=1;
             while j<i
                  %Does the new person have someone else's birthday?
                  if birthday(i)==birthday(j),match=1;,break,end;
                      j=j+1;
                  end
         if match==1,break,end;
     end
     if match==1;, count=1;,end;
     if match==0;, count=0;,end;
     totalcount(a)=totalcount(a)+count;
 end
 prob(a)=totalcount(a)/trialmax;
end
plot(xaxis,prob,'*');       