function rhs ( )

%*****************************************************************************80
%
%% RHS histograms the random harmonic series.
%
%  Discussion:
%
%    Compute and histogram 50,000 values of the partial sums of 
%      sum ( 1 <= k < infinity ) t(i) / k
%    where t(i) is randomly +1 or -1.
%
%  Modified:
%
%    27 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'RHS:\n' );
  fprintf ( 1, '  Random Harmonic Series:\n' ) ;
  fprintf ( 1, '  Compute and histogram 50,000 values of the partial sums of \n' );
  fprintf ( 1, '    sum ( 1 <= k < infinity ) t(i) / k\n' );
  fprintf ( 1, '  where t(i) is randomly +1 or -1.\n' );

  sums = zeros ( 1, 50000 );
  for loop = 1 : 50000
    sum = 0;
    for k = 1 : 100
      t = rand ( );
      if ( t < 0.5 )
        t = 1.0;
      else
        t = -1.0;
      end
      sum = sum + t / k;
    end
    sums(loop) = sum;
  end
%
%  Graphics
%
  clf
  hist ( sums, 50 );
  xlabel ( 'Partial sums of the RHS' );
  ylabel ( 'Number of partial sums' );
  title ( 'RHS: Random Harmonic Series' );
  grid on
  filename = 'rhs.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5 );

  return
end
