% L3B empirical study % If we roll a fair die n times, how often does it happen % that every result (1,2,3,4,5,6) appears equally many times? % Default n=6. function L3Bdicestats(n, rep) if nargin<1, n=6; end if nargin<2, rep=1e3; end tic cpu0 = cputime; nsuccess = 0; for i=1:rep emp = hist(dice(n), 1:6); if all(emp == emp(1)) nsuccess = nsuccess + 1; end if mod(i,10000)==0 fprintf('%d trials in %.2f s...\n', i, cputime-cpu0); end end toc fprintf('%10d trials (of rolling a die %d times)\n', rep, n); fprintf('%10d successes (all bars same height)\n', nsuccess); fprintf('%10.5f success rate\n', nsuccess/rep); end