QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ZigguratGaussianRng< RNG > Class Template Reference

Gaussian random number generator. More...

#include <zigguratgaussianrng.hpp>

+ Collaboration diagram for ZigguratGaussianRng< RNG >:

Public Types

typedef Sample< Realsample_type
 

Public Member Functions

 ZigguratGaussianRng (const RNG &uint64Generator)
 
sample_type next () const
 returns a sample from a Gaussian distribution More...
 
Real nextReal () const
 return a random number from a Gaussian distribution More...
 

Private Types

typedef Real ZigguratTable[257]
 

Private Member Functions

Real pdf (Real x) const
 
Real zeroCase (Real u) const
 compute a random number in the tail by hand More...
 
Real normR () const
 
Real normX (int i) const
 
Real normF (int i) const
 

Private Attributes

RNG uint64Generator_
 

Detailed Description

template<class RNG>
class QuantLib::ZigguratGaussianRng< RNG >

Gaussian random number generator.

It uses the Ziggurat transformation to return a normal distributed Gaussian deviate with average 0.0 and standard deviation of 1.0, from a random integer in the [0,0xffffffffffffffffULL]-interval like.

For a more detailed description see the article "An Improved Ziggurat Method to Generate Normal Random Samples" by Jurgen A. Doornik (https://www.doornik.com/research/ziggurat.pdf).

The code here is inspired by the rust implementation in https://github.com/rust-random/rand/blob/d42daabf65a3ceaf58c2eefc7eb477c4d5a9b4ba/rand_distr/src/normal.rs and https://github.com/rust-random/rand/blob/d42daabf65a3ceaf58c2eefc7eb477c4d5a9b4ba/rand_distr/src/utils.rs.

Class RNG must implement the following interface:

Real nextReal() const;
std::uint64_t nextInt64() const;
Real nextReal() const
return a random number from a Gaussian distribution
QL_REAL Real
real number
Definition: types.hpp:50

Currently, Xoshiro256StarStarUniformRng is the only RNG supporting this.

Definition at line 56 of file zigguratgaussianrng.hpp.

Member Typedef Documentation

◆ sample_type

Definition at line 58 of file zigguratgaussianrng.hpp.

◆ ZigguratTable

typedef Real ZigguratTable[257]
private

Definition at line 72 of file zigguratgaussianrng.hpp.

Constructor & Destructor Documentation

◆ ZigguratGaussianRng()

ZigguratGaussianRng ( const RNG &  uint64Generator)
explicit

Definition at line 60 of file zigguratgaussianrng.hpp.

Member Function Documentation

◆ next()

sample_type next ( ) const

returns a sample from a Gaussian distribution

Definition at line 64 of file zigguratgaussianrng.hpp.

+ Here is the call graph for this function:

◆ nextReal()

Real nextReal

return a random number from a Gaussian distribution

Definition at line 85 of file zigguratgaussianrng.hpp.

+ Here is the caller graph for this function:

◆ pdf()

Real pdf ( Real  x) const
private

Definition at line 125 of file zigguratgaussianrng.hpp.

◆ zeroCase()

Real zeroCase ( Real  u) const
private

compute a random number in the tail by hand

Definition at line 113 of file zigguratgaussianrng.hpp.

◆ normR()

Real normR
private

Definition at line 130 of file zigguratgaussianrng.hpp.

◆ normX()

Real normX ( int  i) const
private

Definition at line 135 of file zigguratgaussianrng.hpp.

◆ normF()

Real normF ( int  i) const
private

Definition at line 206 of file zigguratgaussianrng.hpp.

Member Data Documentation

◆ uint64Generator_

RNG uint64Generator_
private

Definition at line 70 of file zigguratgaussianrng.hpp.