# include <complex>
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <ctime>
# include <cmath>
using namespace std;
# include "normal.hpp"
//****************************************************************************80
complex <float> c4_normal_01 ( int &seed )
//****************************************************************************80
//
// Purpose:
//
// C4_NORMAL_01 returns a unit pseudonormal C4.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, complex <float> C4_NORMAL_01, a unit pseudonormal value.
//
{
const float r4_pi = 3.141592653589793;
float v1;
float v2;
complex <float> value;
float x_c;
float x_r;
v1 = r4_uniform_01 ( seed );
v2 = r4_uniform_01 ( seed );
x_r = sqrt ( - 2.0 * log ( v1 ) ) * cos ( 2.0 * r4_pi * v2 );
x_c = sqrt ( - 2.0 * log ( v1 ) ) * sin ( 2.0 * r4_pi * v2 );
value = complex <float> ( x_r, x_c );
return value;
}
//****************************************************************************80
complex <double> c8_normal_01 ( int &seed )
//****************************************************************************80
//
// Purpose:
//
// C8_NORMAL_01 returns a unit pseudonormal C8.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, complex <double> C8_NORMAL_01, a unit pseudonormal value.
//
{
const double r8_pi = 3.141592653589793;
double v1;
double v2;
complex <double> value;
double x_c;
double x_r;
v1 = r8_uniform_01 ( seed );
v2 = r8_uniform_01 ( seed );
x_r = sqrt ( - 2.0 * log ( v1 ) ) * cos ( 2.0 * r8_pi * v2 );
x_c = sqrt ( - 2.0 * log ( v1 ) ) * sin ( 2.0 * r8_pi * v2 );
value = complex <double> ( x_r, x_c );
return value;
}
//****************************************************************************80
int i4_normal_ab ( float a, float b, int &seed )
//****************************************************************************80
//
// Purpose:
//
// I4_NORMAL_AB returns a scaled pseudonormal I4.
//
// Discussion:
//
// The normal probability distribution function (PDF) is sampled,
// with mean A and standard deviation B.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, float A, the mean of the PDF.
//
// Input, float B, the standard deviation of the PDF.
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, int I4_NORMAL_AB, a sample of the normal PDF.
//
{
int value;
int value_float;
value_float = a + b * r4_normal_01 ( seed );
value = ( int ) ( value_float );
return value;
}
//****************************************************************************80
long long int i8_normal_ab ( double a, double b, long long int &seed )
//****************************************************************************80
//
// Purpose:
//
// I8_NORMAL_AB returns a scaled pseudonormal I8.
//
// Discussion:
//
// The normal probability distribution function (PDF) is sampled,
// with mean A and standard deviation B.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, double A, the mean of the PDF.
//
// Input, double B, the standard deviation of the PDF.
//
// Input/output, long long int &SEED, a seed for the random number generator.
//
// Output, long long int I8_NORMAL_AB, a sample of the normal PDF.
//
{
int seed_int;
double value_double;
long long int value_long_long_int;
seed_int = ( int ) seed;
value_double = a + b * r8_normal_01 ( seed_int );
if ( value_double < 0.0 )
{
value_long_long_int = ( long long int ) ( value_double - 0.5 );
}
else
{
value_long_long_int = ( long long int ) ( value_double + 0.5 );
}
seed = ( long long int ) seed_int;
return value_long_long_int;
}
//****************************************************************************80
float r4_normal_01 ( int &seed )
//****************************************************************************80
//
// Purpose:
//
// R4_NORMAL_01 returns a unit pseudonormal R4.
//
// Discussion:
//
// The standard normal probability distribution function (PDF) has
// mean 0 and standard deviation 1.
//
// The Box-Muller method is used, which is efficient, but
// generates two values at a time.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 06 August 2013
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, float R4_NORMAL_01, a normally distributed random value.
//
{
const float r4_pi = 3.141592653589793;
float r1;
float r2;
float x;
r1 = r4_uniform_01 ( seed );
r2 = r4_uniform_01 ( seed );
x = sqrt ( - 2.0 * log ( r1 ) ) * cos ( 2.0 * r4_pi * r2 );
return x;
}
//****************************************************************************80
float r4_normal_ab ( float a, float b, int &seed )
//****************************************************************************80
//
// Purpose:
//
// R4_NORMAL_AB returns a scaled pseudonormal R4.
//
// Discussion:
//
// The normal probability distribution function (PDF) is sampled,
// with mean A and standard deviation B.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, float A, the mean of the PDF.
//
// Input, float B, the standard deviation of the PDF.
//
// Input/output, int &SEED, a seed for the random number generator.
//
// Output, float R4_NORMAL_AB, a sample of the normal PDF.
//
{
float value;
value = a + b * r4_normal_01 ( seed );
return value;
}
//****************************************************************************80
float r4_uniform_01 ( int &seed )
//****************************************************************************80
//
// Purpose:
//
// R4_UNIFORM_01 returns a unit pseudorandom R4.
//
// Discussion:
//
// This routine implements the recursion
//
// seed = 16807 * seed mod ( 2^31 - 1 )
// r4_uniform_01 = seed / ( 2^31 - 1 )
//
// The integer arithmetic never requires more than 32 bits,
// including a sign bit.
//
// If the initial seed is 12345, then the first three computations are
//
// Input Output R4_UNIFORM_01
// SEED SEED
//
// 12345 207482415 0.096616
// 207482415 1790989824 0.833995
// 1790989824 2035175616 0.947702
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 09 April 2012
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Paul Bratley, Bennett Fox, Linus Schrage,
// A Guide to Simulation,
// Springer Verlag, pages 201-202, 1983.
//
// Pierre L'Ecuyer,
// Random Number Generation,
// in Handbook of Simulation
// edited by Jerry Banks,
// Wiley Interscience, page 95, 1998.