function two_dice ( n )
%
%  Simulate N throws of two fair dice.
%
  pdf = [0,1,2,3,4,5,6,5,4,3,2,1] / 36;
%
%  Compute the CDF:
%
  cdf = cumsum ( pdf );
%
%  Throw N times:
%
  r = rand ( n, 1 );
%
%  Each R corresponds to an X for which CDF(X-1) < R <= CDF(X).
%
  for x = 2 : 12
    match = ( cdf(x-1) < r & r <= cdf(x) );
    score ( match ) = x;
  end
%
%  Compute the frequency and estimated probability of each score X.
%
  for x = 1 : 12
    match = find ( score == x );
    freq(x) = length ( match );
  end

  for x = 1 : 12
    pdf_est(x) = freq(x) / n;
  end

