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 Member Functions | Private Attributes | List of all members
ZigguratRng Class Reference

Ziggurat random-number generator. More...

#include <zigguratrng.hpp>

+ Collaboration diagram for ZigguratRng:

Public Types

typedef Sample< Realsample_type
 

Public Member Functions

 ZigguratRng (unsigned long seed=0)
 
sample_type next () const
 

Private Member Functions

Real nextGaussian () const
 

Private Attributes

MersenneTwisterUniformRng mt32_
 

Detailed Description

Ziggurat random-number generator.

This generator returns standard normal variates using the Ziggurat method. The underlying RNG is mt19937 (32 bit version). The algorithm is described in Marsaglia and Tsang (2000). "The Ziggurat Method for Generating Random Variables". Journal of Statistical Software 5 (8). Note that step 2 from the above paper reuses the rightmost 8 bits of the random integer, which creates correlation between steps 1 and

  1. This implementation was written from scratch, following Marsaglia and Tsang. It avoids the correlation by using only the leftmost 24 bits of mt19937's output.

Note that the GNU GSL implementation uses a different value for the right-most step. The GSL value is somewhat different from the one reported by Marsaglia and Tsang because GSL uses a different tail. This implementation uses the same right-most step as reported by Marsaglia and Tsang. The generator was put through Marsaglia's Diehard battery of tests and didn't exibit any abnormal behavior.

Definition at line 52 of file zigguratrng.hpp.

Member Typedef Documentation

◆ sample_type

Definition at line 54 of file zigguratrng.hpp.

Constructor & Destructor Documentation

◆ ZigguratRng()

ZigguratRng ( unsigned long  seed = 0)
explicit

Definition at line 209 of file zigguratrng.cpp.

Member Function Documentation

◆ next()

sample_type next ( ) const

Definition at line 56 of file zigguratrng.hpp.

+ Here is the call graph for this function:

◆ nextGaussian()

Real nextGaussian ( ) const
private

Definition at line 212 of file zigguratrng.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mt32_

MersenneTwisterUniformRng mt32_
mutableprivate

Definition at line 59 of file zigguratrng.hpp.