function demere2(numreps,numrolls) % How many rolls until we get a double-six? Here numreps is the number of % trials and numrolls is an optional argument, the number of rolls per % trial (which is taken to be 25 if no value is given). % % If you want a plot, uncomment the line with the plot command. reps=numreps; rec=NaN(1,reps); % where we'll keep the record p=1/36; % prob of success on a given roll for k=1:reps n=1; while rand>p n=n+1; % one more try end rec(k)=n; end if nargin < 2 % check to see if the optional numrolls is given and if not use 25 numrolls = 25; end % plot(sort(rec)) disp(['The proportion of trials with a double 6 in the first ', num2str(numrolls), ' is ', num2str(length(find(rec<=numrolls))/reps)])