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
KnuthUniformRng Class Reference

Uniform random number generator. More...

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

+ Collaboration diagram for KnuthUniformRng:

Public Types

typedef Sample< Realsample_type
 

Public Member Functions

 KnuthUniformRng (long seed=0)
 
sample_type next () const
 

Private Member Functions

double mod_sum (double x, double y) const
 
bool is_odd (int s) const
 
void ranf_start (long seed)
 
void ranf_array (std::vector< double > &aa, int n) const
 
double ranf_arr_cycle () const
 

Private Attributes

std::vector< double > ranf_arr_buf
 
size_t ranf_arr_ptr
 
size_t ranf_arr_sentinel
 
std::vector< double > ran_u
 

Static Private Attributes

static const int KK = 100
 
static const int LL = 37
 
static const int TT = 70
 
static const int QUALITY = 1009
 

Detailed Description

Uniform random number generator.

Random number generator by Knuth. For more details see Knuth, Seminumerical Algorithms, 3rd edition, Section 3.6.

Note
This is not Knuth's original implementation which is available at http://www-cs-faculty.stanford.edu/~knuth/programs.html, but rather a slightly modified version wrapped in a C++ class. Such modifications did not affect the code but only the data structures used, which were converted to their standard C++ equivalents.

Definition at line 44 of file knuthuniformrng.hpp.

Member Typedef Documentation

◆ sample_type

Definition at line 46 of file knuthuniformrng.hpp.

Constructor & Destructor Documentation

◆ KnuthUniformRng()

KnuthUniformRng ( long  seed = 0)
explicit

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

Definition at line 30 of file knuthuniformrng.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ next()

returns a sample with weight 1.0 containing a random number uniformly chosen from (0.0,1.0)

Definition at line 68 of file knuthuniformrng.hpp.

+ Here is the call graph for this function:

◆ mod_sum()

double mod_sum ( double  x,
double  y 
) const
private

Definition at line 75 of file knuthuniformrng.hpp.

+ Here is the caller graph for this function:

◆ is_odd()

bool is_odd ( int  s) const
private

Definition at line 79 of file knuthuniformrng.hpp.

+ Here is the caller graph for this function:

◆ ranf_start()

void ranf_start ( long  seed)
private

Definition at line 36 of file knuthuniformrng.cpp.

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

◆ ranf_array()

void ranf_array ( std::vector< double > &  aa,
int  n 
) const
private

Definition at line 75 of file knuthuniformrng.cpp.

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

◆ ranf_arr_cycle()

double ranf_arr_cycle ( ) const
private

Definition at line 84 of file knuthuniformrng.cpp.

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

Member Data Documentation

◆ KK

const int KK = 100
staticprivate

Definition at line 54 of file knuthuniformrng.hpp.

◆ LL

const int LL = 37
staticprivate

Definition at line 54 of file knuthuniformrng.hpp.

◆ TT

const int TT = 70
staticprivate

Definition at line 54 of file knuthuniformrng.hpp.

◆ QUALITY

const int QUALITY = 1009
staticprivate

Definition at line 54 of file knuthuniformrng.hpp.

◆ ranf_arr_buf

std::vector<double> ranf_arr_buf
mutableprivate

Definition at line 55 of file knuthuniformrng.hpp.

◆ ranf_arr_ptr

size_t ranf_arr_ptr
mutableprivate

Definition at line 56 of file knuthuniformrng.hpp.

◆ ranf_arr_sentinel

size_t ranf_arr_sentinel
private

Definition at line 56 of file knuthuniformrng.hpp.

◆ ran_u

std::vector<double> ran_u
mutableprivate

Definition at line 57 of file knuthuniformrng.hpp.