Public Types | Public Member Functions
RandomLib::NormalDistribution Class Reference

Normal deviates. More...

#include <RandomLib-2010-01/NormalDistribution.hpp>

List of all members.

Public Types

typedef RealType result_type

Public Member Functions

template<class Random >
RealType operator() (Random &r, RealType mu=RealType(0), RealType sigma=RealType(1)) const throw ()

Detailed Description

Normal deviates.

Sample from the normal distribution.

This uses the ratio method; see Knuth, TAOCP, Vol 2, Sec. 3.4.1.C, Algorithm R. Unlike the Box-Muller method which generates two normal deviates at a time, this method generates just one. This means that this class has no state that needs to be saved when checkpointing a calculation. Original citation is
A. J. Kinderman, J. F. Monahan,
Computer Generation of Random Variables Using the Ratio of Uniform Deviates,
ACM TOMS 3, 257-260 (1977).

Improved "quadratic" bounds are given by
J. L. Leva,
A Fast Normal Random Number Generator,
ACM TOMS 18, 449-453 and 454-455 (1992).

The log is evaluated 1.369 times per normal deviate with no bounds, 0.232 times with Knuth's bounds, and 0.012 times with the quadratic bounds. Time is approx 0.3 us per deviate (1GHz machine, optimized, RealType = float).

Example

   #include "RandomLib/NormalDistribution.hpp"

   RandomLib::Random r;
   std::cout << "Seed set to " << r.SeedString() << std::endl;
   RandomLib::NormalDistribution<double> normdist;
   std::cout << "Select from normal distribution:";
   for (size_t i = 0; i < 10; ++i)
       std::cout << " " << normdist(r);
   std::cout << std::endl;

Member Typedef Documentation

The type returned by NormalDistribution::operator()(Random&)

Definition at line 56 of file NormalDistribution.hpp.


Member Function Documentation

template<class Random >
RealType RandomLib::NormalDistribution::operator() ( Random r,
RealType  mu = RealType(0),
RealType  sigma = RealType(1) 
) const throw () [inline]

Return a sample of type RealType from the normal distribution with mean mu and standard deviation sigma.

For mu = 0 and sigma = 1 (the defaults), the distribution is symmetric about zero and is nonzero. The maximum result is less than 2 sqrt(log(2) p) where p is the precision of real type RealType. The minimum positive value is approximately 1/2p+1. Here p is the precision of real type RealType.

Definition at line 73 of file NormalDistribution.hpp.


The documentation for this class was generated from the following file: