NEST  2.6.0,not_revisioned_source_dir@0
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
librandom::KnuthLFG Class Reference

Built-in implementation of Knuth's Lagged Fibonacci generator. More...

#include <knuthlfg.h>

Inheritance diagram for librandom::KnuthLFG:
librandom::RandomGen

Public Member Functions

 KnuthLFG (unsigned long)
 Create generator with given seed. More...
 
 ~KnuthLFG ()
 
RngPtr clone (unsigned long s)
 clone a random number generator of same type initialized with given seed More...
 
- Public Member Functions inherited from librandom::RandomGen
 RandomGen ()
 
virtual ~RandomGen ()
 
double drand (void)
 The following functions implement the user interface of the RandomGen class, including buffer management. More...
 
double operator() (void)
 draw from [0, 1) More...
 
double drandpos (void)
 draw from (0, 1) More...
 
unsigned long ulrand (const unsigned long)
 draw from [0, n-1] More...
 
void seed (const unsigned long)
 set random seed to a new value More...
 
size_t get_buffsize (void) const
 returns buffer size More...
 
void set_buffsize (const size_t)
 set buffer size More...
 

Private Member Functions

void seed_ (unsigned long)
 implements seeding for RandomGen More...
 
double drand_ ()
 implements drawing a single [0,1) number for RandomGen More...
 
void ran_array_ (std::vector< long > &rbuff)
 Generates numbers, refilling buffer. More...
 
void ran_start_ (long seed)
 initializes buffer More...
 
long ran_draw_ ()
 deliver integer random number from ran_buffer_ More...
 
void self_test_ ()
 Perform minimal self-test given by Knuth. More...
 

Static Private Member Functions

static long mod_diff_ (long, long)
 subtraction module MM More...
 
static bool is_odd_ (long)
 

Private Attributes

std::vector< long > ran_x_
 the generator state More...
 
std::vector< long > ran_buffer_
 generated numbers, 0..KK-1 are shipped More...
 
const std::vector< long >
::const_iterator 
end_
 marker past last to deliver More...
 
std::vector< long >::const_iterator next_
 next number to deliver More...
 

Static Private Attributes

static const long KK_ = 100
 the long lag More...
 
static const long LL_ = 37
 the short lag More...
 
static const long MM_ = 1L << 30
 the modulus More...
 
static const long TT_ = 70
 guaranteed separation between streams More...
 
static const long QUALITY_ = 1009
 number of RNGs to fill for each cycle More...
 
static const double I2DFactor_ = 1.0 / librandom::KnuthLFG::MM_
 int to double factor More...
 

Additional Inherited Members

- Static Public Member Functions inherited from librandom::RandomGen
static RngPtr create_knuthlfg_rng (unsigned long)
 Create built-in Knuth Lagged Fibonacci random generator. More...
 
- Static Public Attributes inherited from librandom::RandomGen
static const unsigned long DefaultSeed = 0xd37ca59fUL
 Default value for seeding generators in places where no seed is supplied. More...
 

Detailed Description

Built-in implementation of Knuth's Lagged Fibonacci generator.

This implementation is directly derived from Knuth's C code and generates the same random number sequence as the GSL implementation.

Constructor & Destructor Documentation

librandom::KnuthLFG::KnuthLFG ( unsigned long  seed)
explicit

Create generator with given seed.

References ran_start_(), and self_test_().

Referenced by clone().

librandom::KnuthLFG::~KnuthLFG ( )
inline

Member Function Documentation

RngPtr librandom::KnuthLFG::clone ( unsigned long  long)
inlinevirtual

clone a random number generator of same type initialized with given seed

Implements librandom::RandomGen.

References KnuthLFG().

double librandom::KnuthLFG::drand_ ( void  )
inlineprivatevirtual

implements drawing a single [0,1) number for RandomGen

Implements librandom::RandomGen.

References I2DFactor_, and ran_draw_().

bool librandom::KnuthLFG::is_odd_ ( long  x)
inlinestaticprivate
long librandom::KnuthLFG::mod_diff_ ( long  x,
long  y 
)
inlinestaticprivate

subtraction module MM

References MM_.

void librandom::KnuthLFG::ran_array_ ( std::vector< long > &  rbuff)
private

Generates numbers, refilling buffer.

Note
Buffer must be passed as argument, since ran_start_() and self_test_() must pass other buffers than ran_buffer_.

References nest::names::n.

Referenced by ran_draw_().

long librandom::KnuthLFG::ran_draw_ ( )
inlineprivate

deliver integer random number from ran_buffer_

References end_, next_, ran_array_(), and ran_buffer_.

Referenced by drand_().

void librandom::KnuthLFG::ran_start_ ( long  seed)
private

initializes buffer

References nest::names::x.

Referenced by KnuthLFG(), and seed_().

void librandom::KnuthLFG::seed_ ( unsigned long  seed)
inlineprivatevirtual

implements seeding for RandomGen

Implements librandom::RandomGen.

References ran_start_().

void librandom::KnuthLFG::self_test_ ( )
private

Perform minimal self-test given by Knuth.

The test will break an assertion if it fails. This is acceptable, since failure indicates either lack of two's complement arithmetic or problems with the size of data types.

References assert().

Referenced by KnuthLFG().

Member Data Documentation

const std::vector<long>::const_iterator librandom::KnuthLFG::end_
private

marker past last to deliver

Referenced by ran_draw_().

const double librandom::KnuthLFG::I2DFactor_ = 1.0 / librandom::KnuthLFG::MM_
staticprivate

int to double factor

Referenced by drand_().

const long librandom::KnuthLFG::KK_ = 100
staticprivate

the long lag

const long librandom::KnuthLFG::LL_ = 37
staticprivate

the short lag

const long librandom::KnuthLFG::MM_ = 1L << 30
staticprivate

the modulus

Referenced by mod_diff_().

std::vector<long>::const_iterator librandom::KnuthLFG::next_
private

next number to deliver

Referenced by ran_draw_().

const long librandom::KnuthLFG::QUALITY_ = 1009
staticprivate

number of RNGs to fill for each cycle

std::vector<long> librandom::KnuthLFG::ran_buffer_
private

generated numbers, 0..KK-1 are shipped

Referenced by ran_draw_().

std::vector<long> librandom::KnuthLFG::ran_x_
private

the generator state

const long librandom::KnuthLFG::TT_ = 70
staticprivate

guaranteed separation between streams


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