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 GNU LGPL license.
#
#  Modified:
#
#    08 February 2023
#
#  Author:
#
#    Original MATLAB version by Paul Nahin.
#    This version by John Burkardt.
#
#  Reference:
#
#    Paul Nahin,
#    Dueling Idiots and Other Probability Puzzlers,
#    Princeton, 2012,
#    ISBN: 978-0691155005.
#
  print ( '' )
  print ( 'onewaytodoit():' )
  print ( '  This program generates 10,000 normal random values using the ' )
  print ( '  Box-Muller transformation on uniform rnadom numbers.' )
  print ( '  Display results as a histogram.' )

  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 ( 'number of numbers in each bin' )
  filename = 'onewaytodoit.png'
  plt.savefig ( filename )
  print ( '  Graphics saved as "' + filename + '"' )
  plt.close ( )

  return
end
