function onewaytodoit ( )

%*****************************************************************************80
%
%% onewaytodoit() shows how to generate normal random values.
%
%  Discussion:
%
%    This code generates 10,000 normal random values by using the 
%    Box-Muller transformation on uniform random numbers.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'onewaytodoit():\n' );
  fprintf ( 1, '  This program generates 10,000 normal random values using the \n' );
  fprintf ( 1, '  Box-Muller transformation on uniform rnadom numbers.\n' );
  fprintf ( 1, '  Display results as a histogram.\n' );

  scale = 2 * pi;
  for i = 1 : 2 : 10000
    u = rand ( );
    theta = scale * rand ( );
    factor = sqrt ( - 2 * log ( u ) );
    x1 = factor * cos ( theta );
    x2 = factor * sin ( theta );
    y(i) = x1;
    y(i+1) = x2;
  end
%
%  Graphics.
%
  clf ( );
  hist ( y, 100 );
  grid ( 'on' );
  title ( 'Histogram of a Normal Random Number Generator' );
  xlabel ( '100 bins, 10,000 numbers' );
  ylabel ( 'bin population' );
  filename = 'onewaytodoit.png';
  print ( '-dpng', filename );
  fprintf ( '  Graphics saved as "%s"\n', filename );

  return
end
