Very Simple Cross-Platform Library
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
hu::varadiistvan::scpl::PseudoRandom Class Reference

#include <PseudoRandom.h>

Public Member Functions

 PseudoRandom ()
 
 PseudoRandom (uint32_t seed)
 
uint32_t next ()
 
unsigned nextUnsigned (unsigned to=MAX, unsigned from=0)
 
double nextDouble (double to=1.0, double from=0.0)
 

Static Public Attributes

static const uint32_t MAX = (1<<31)
 

Private Member Functions

void initialize (uint32_t seed)
 

Private Attributes

uint32_t vector [vectorSize]
 
int nextIndex
 

Static Private Attributes

static const size_t vectorSize = 34
 
static const size_t numDiscarded = 344
 

Detailed Description

A pseudo-random number generator. The algorithm is the same as described in http://www.mathstat.dal.ca/~selinger/random, i.e. the GNU libc random number generator. It is reimplemented, because Windows does not provide a thread-safe, reentrable pseudo-random number generation facility, so it should have been implemented for Win32 anyway.

Definition at line 52 of file PseudoRandom.h.

Constructor & Destructor Documentation

◆ PseudoRandom() [1/2]

hu::varadiistvan::scpl::PseudoRandom::PseudoRandom ( )
inline

Construct the random number generator with a default seed (taken by calling time()).

Definition at line 121 of file PseudoRandom.h.

◆ PseudoRandom() [2/2]

hu::varadiistvan::scpl::PseudoRandom::PseudoRandom ( uint32_t  seed)
inline

Construct the random number generator with the given seed.

Definition at line 128 of file PseudoRandom.h.

Member Function Documentation

◆ initialize()

void PseudoRandom::initialize ( uint32_t  seed)
private

Initialize the random number generator with the given seed.

Definition at line 39 of file PseudoRandom.cc.

◆ next()

uint32_t hu::varadiistvan::scpl::PseudoRandom::next ( )
inline

Get the next raw value.

Definition at line 135 of file PseudoRandom.h.

◆ nextDouble()

double hu::varadiistvan::scpl::PseudoRandom::nextDouble ( double  to = 1.0,
double  from = 0.0 
)
inline

Get the next random number as a double value between [from, to].

Definition at line 158 of file PseudoRandom.h.

◆ nextUnsigned()

unsigned hu::varadiistvan::scpl::PseudoRandom::nextUnsigned ( unsigned  to = MAX,
unsigned  from = 0 
)
inline

Get the next random number as an unsigned value between [from, to].

Definition at line 150 of file PseudoRandom.h.

Member Data Documentation

◆ MAX

const uint32_t hu::varadiistvan::scpl::PseudoRandom::MAX = (1<<31)
static

The largest random number generated in the unconverted sequence.

Definition at line 59 of file PseudoRandom.h.

◆ nextIndex

int hu::varadiistvan::scpl::PseudoRandom::nextIndex
private

The index of the next random number.

Definition at line 80 of file PseudoRandom.h.

◆ numDiscarded

const size_t hu::varadiistvan::scpl::PseudoRandom::numDiscarded = 344
staticprivate

The number of random numbers thrown away.

Definition at line 70 of file PseudoRandom.h.

◆ vector

uint32_t hu::varadiistvan::scpl::PseudoRandom::vector[vectorSize]
private

The vector of random numbers used to generate the next one.

Definition at line 75 of file PseudoRandom.h.

◆ vectorSize

const size_t hu::varadiistvan::scpl::PseudoRandom::vectorSize = 34
staticprivate

The size of the vector.

Definition at line 65 of file PseudoRandom.h.


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