NCBI C++ ToolKit
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
CRandom Class Reference

Search Toolkit Book for CRandom

CRandom:: More...

#include <util/random_gen.hpp>

+ Inheritance diagram for CRandom:

Public Types

enum  EGetRandMethod { eGetRand_LFG , eGetRand_Sys }
 Random generator to use in the GetRand() functions. More...
typedef Uint4 TValue
 Type of the generated integer value and/or the seed value. More...

Public Member Functions

 CRandom (EGetRandMethod method=eGetRand_LFG)
 If "method" is: More...
 CRandom (TValue seed)
 Use LFG random generator seeded with "seed". More...
TValue GetRand (void)
 Get the next random number in the interval [0..GetMax()] (inclusive) More...
TValue GetRand (TValue min_value, TValue max_value)
 Get random number in the interval [min_value..max_value] (inclusive) More...
Uint8 GetRandUint8 (void)
 Get random Uint8 number. More...
Uint8 GetRandUint8 (Uint8 min_value, Uint8 max_value)
 Get random number in the interval [min_value..max_value] (inclusive) More...
size_t GetRandSize_t (size_t min_value, size_t max_value)
 Get random number in the interval [min_value..max_value] (inclusive) More...
TValue GetRandIndex (TValue size)
 Get random number in the interval [0..size-1] (e.g. More...
Uint8 GetRandIndexUint8 (Uint8 size)
 Get random number in the interval [0..size-1] (e.g. More...
size_t GetRandIndexSize_t (size_t size)
 Get random number in the interval [0..size-1] (e.g. More...
EGetRandMethod GetRandMethod (void) const
 Get the random generator type. More...
void Randomize (void)
 Re-initialize (re-seed) the generator using platform-specific randomization. More...
void SetSeed (TValue seed)
 Seed the random number generator with "seed". More...
TValue GetSeed (void) const
 Get the last set seed (LFG only) More...
void Reset (void)
 Reset random number generator to initial startup condition (LFG only) More...

Static Public Member Functions

static TValue GetMax (void)
 The max. value GetRand() returns. More...

Private Types

enum  { kStateSize = 33 }

Private Member Functions

TValue x_GetRand32Bits (void)
Uint8 x_GetRand64Bits (void)
TValue x_GetSysRand32Bits (void) const
 CRandom (const CRandom &)
CRandomoperator= (const CRandom &)

Private Attributes

EGetRandMethod m_RandMethod
TValue m_State [kStateSize]
int m_RJ
int m_RK
TValue m_Seed

Detailed Description


Wraps a system-dependent random generator (could be slow due to system calls), and implements lagged Fibonacci (LFG) random number generator with lags 33 and 13, modulus 2^31, and operation '+'

LFG is a slightly modified version of Nlm_Random() found in the NCBI C toolkit. It generates uniform random numbers between 0 and 2^31 - 1 (inclusive). It can be 100 times faster than system-dependent one.

More details and literature refs are provided in "random_gen.cpp".

Definition at line 65 of file random_gen.hpp.

The documentation for this class was generated from the following files:
Modified on Mon Jun 17 05:04:09 2024 by rev. 669887