RandomLib
1.10
|
Normal deviates. More...
#include <RandomLib/NormalDistribution.hpp>
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 () |
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
RealType | the real type of the results (default double). |
Definition at line 55 of file NormalDistribution.hpp.
typedef RealType RandomLib::NormalDistribution< RealType >::result_type |
The type returned by NormalDistribution::operator()(Random&)
Definition at line 60 of file NormalDistribution.hpp.
|
inline |
Return a sample of type RealType from the normal distribution with mean μ and standard deviation σ.
For μ = 0 and σ = 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.
Random | the type of RandomCanonical generator. |
[in,out] | r | the RandomCanonical generator. |
[in] | mu | the mean value of the normal distribution (default 0). |
[in] | sigma | the standard deviation of the normal distribution (default 1). |
Definition at line 84 of file NormalDistribution.hpp.