function xplusy ( trial_num, n )

%*****************************************************************************80
%
%% xplusy() creates a histogram of the sum of n random variables.
%
%  Discussion:
%
%    This code produces values of the sum of n random
%    variables, each variable uniform from 0 to 1, and independent.
%    It then plots a histogram of the sums using 100 bins.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input:
%
%    integer trial_num: the number of trials.
%
%    integer n: the number of variables in each sum.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'xplusy():\n' );
  fprintf ( 1, '  Produce %d values of the sum of %d random\n', trial_num, n );
  fprintf ( 1, '  variables, each variable uniform from 0 to 1, and independent.\n' );
  fprintf ( 1, '  Plot a histogram of the sums using 100 bins.\n' );

  mean = n / 2.0;
  sd = sqrt ( n / 12.0 );

  for sumn = 1 : trial_num
    s = 0.0;
    for i = 1 : n
      s = s + rand ( );
    end
    s = ( s - mean ) / sd;
    z(sumn) = s;
  end
%
%  Graphics.
%
  clf ( );
  hist ( z, 100 );
  grid ( 'on' );
  xlabel ( 'sum' );
  ylabel ( 'number of values per bin' );
  label = sprintf ( 'Histogram of the sum of %d Random Variables', n )
  title ( label );
  filename = 'xplusy.png';
  print ( '-dpng', filename );
  fprintf ( '  Graphics saved as "%s"\n', filename );

  return
end
