QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
MersenneTwisterUniformRng Class Reference

Uniform random number generator. More...

#include <ql/math/randomnumbers/mt19937uniformrng.hpp>

+ Collaboration diagram for MersenneTwisterUniformRng:

Public Types

typedef Sample< Realsample_type
 

Public Member Functions

 MersenneTwisterUniformRng (unsigned long seed=0)
 
 MersenneTwisterUniformRng (const std::vector< unsigned long > &seeds)
 
sample_type next () const
 
Real nextReal () const
 return a random number in the (0.0, 1.0)-interval More...
 
unsigned long nextInt32 () const
 return a random integer in the [0,0xffffffff]-interval More...
 

Private Member Functions

void seedInitialization (unsigned long seed)
 
void twist () const
 

Private Attributes

unsigned long mt [N]
 
Size mti
 

Static Private Attributes

static const Size N = 624
 
static const Size M = 397
 
static const unsigned long MATRIX_A = 0x9908b0dfUL
 
static const unsigned long UPPER_MASK =0x80000000UL
 
static const unsigned long LOWER_MASK =0x7fffffffUL
 

Detailed Description

Uniform random number generator.

Mersenne Twister random number generator of period 2**19937-1

For more details see http://www.math.keio.ac.jp/matumoto/emt.html

Tests:
the correctness of the returned values is tested by checking them against known good results.
Examples
GlobalOptimizer.cpp.

Definition at line 41 of file mt19937uniformrng.hpp.

Member Typedef Documentation

◆ sample_type

Definition at line 46 of file mt19937uniformrng.hpp.

Constructor & Destructor Documentation

◆ MersenneTwisterUniformRng() [1/2]

MersenneTwisterUniformRng ( unsigned long  seed = 0)
explicit

if the given seed is 0, a random seed will be chosen based on clock()

Definition at line 82 of file mt19937uniformrng.cpp.

+ Here is the call graph for this function:

◆ MersenneTwisterUniformRng() [2/2]

MersenneTwisterUniformRng ( const std::vector< unsigned long > &  seeds)
explicit

Definition at line 102 of file mt19937uniformrng.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ next()

sample_type next ( ) const

returns a sample with weight 1.0 containing a random number in the (0.0, 1.0) interval

Definition at line 54 of file mt19937uniformrng.hpp.

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

◆ nextReal()

Real nextReal ( ) const

return a random number in the (0.0, 1.0)-interval

Definition at line 56 of file mt19937uniformrng.hpp.

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

◆ nextInt32()

unsigned long nextInt32 ( ) const

return a random integer in the [0,0xffffffff]-interval

Definition at line 60 of file mt19937uniformrng.hpp.

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

◆ seedInitialization()

void seedInitialization ( unsigned long  seed)
private

Definition at line 86 of file mt19937uniformrng.cpp.

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

◆ twist()

void twist ( ) const
private

Definition at line 125 of file mt19937uniformrng.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ N

const Size N = 624
staticprivate

Definition at line 43 of file mt19937uniformrng.hpp.

◆ M

const Size M = 397
staticprivate

Definition at line 44 of file mt19937uniformrng.hpp.

◆ mt

unsigned long mt[N]
mutableprivate

Definition at line 76 of file mt19937uniformrng.hpp.

◆ mti

Size mti
mutableprivate

Definition at line 77 of file mt19937uniformrng.hpp.

◆ MATRIX_A

const unsigned long MATRIX_A = 0x9908b0dfUL
staticprivate

Definition at line 78 of file mt19937uniformrng.hpp.

◆ UPPER_MASK

const unsigned long UPPER_MASK =0x80000000UL
staticprivate

Definition at line 78 of file mt19937uniformrng.hpp.

◆ LOWER_MASK

const unsigned long LOWER_MASK =0x7fffffffUL
staticprivate

Definition at line 78 of file mt19937uniformrng.hpp.