RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Types | Public Member Functions | List of all members
RandomLib::NormalDistribution< RealType > Class Template Reference

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 ()

Detailed Description

template<typename RealType = double>
class RandomLib::NormalDistribution< RealType >

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).


std::cout << "Seed set to " << r.SeedString() << "\n";
std::cout << "Select from normal distribution:";
for (size_t i = 0; i < 10; ++i)
std::cout << " " << normdist(r);
std::cout << "\n";
Template Parameters
RealTypethe real type of the results (default double).

Definition at line 55 of file NormalDistribution.hpp.

Member Typedef Documentation

template<typename RealType = double>
typedef RealType RandomLib::NormalDistribution< RealType >::result_type

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

Definition at line 60 of file NormalDistribution.hpp.

Member Function Documentation

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

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.

Template Parameters
Randomthe type of RandomCanonical generator.
[in,out]rthe RandomCanonical generator.
[in]muthe mean value of the normal distribution (default 0).
[in]sigmathe standard deviation of the normal distribution (default 1).
the random sample.

Definition at line 84 of file NormalDistribution.hpp.

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