SST 12.1.0
Structural Simulation Toolkit
SST::RNG::MarsagliaRNG Class Reference

Implements a random number generator using the Marsaglia method. More...

#include "sst/core/rng/marsaglia.h"

Inheritance diagram for SST::RNG::MarsagliaRNG:
SST::RNG::Random

Public Member Functions

 MarsagliaRNG (unsigned int initial_z, unsigned int initial_w)
 Creates a new Marsaglia RNG using the initial seeds. More...
 
 MarsagliaRNG ()
 Creates a new Marsaglia RNG using random initial seeds (which are read from the system clock). More...
 
void restart (unsigned int new_z, unsigned int new_w)
 Restart the random number generator with new seeds. More...
 
double nextUniform () override
 Generates the next random number as a double in the range 0 to 1. More...
 
uint32_t generateNextUInt32 () override
 Generates the next random number as an unsigned 32-bit integer. More...
 
uint64_t generateNextUInt64 () override
 Generates the next random number as an unsigned 64-bit integer. More...
 
int64_t generateNextInt64 () override
 Generates the next number as a signed 64-bit integer. More...
 
int32_t generateNextInt32 () override
 Generates the next number as a signed 32-bit integer. More...
 
void seed (uint64_t newSeed)
 Seed the XOR RNG.
 
- Public Member Functions inherited from SST::RNG::Random
virtual double nextUniform ()=0
 Generates the next random number in the range [0,1). More...
 
virtual uint32_t generateNextUInt32 ()=0
 Generates the next random number as an unsigned 32-bit integer. More...
 
virtual uint64_t generateNextUInt64 ()=0
 Generates the next random number as an unsigned 64-bit integer. More...
 
virtual int64_t generateNextInt64 ()=0
 Generates the next random number as a signed 64-bit integer. More...
 
virtual int32_t generateNextInt32 ()=0
 Generates the next random number as a signed 32-bit integer. More...
 
virtual ~Random ()
 Destroys the random number generator.
 

Detailed Description

Implements a random number generator using the Marsaglia method.

This method is computationally cheap and provides a reasonable distribution of random numbers. If you need additional strength in the random numbers you may want to consider the Mersenne RNG.

For more information see the Multiply-with-carry Random Number Generator article

at Wikipedia (http://en.wikipedia.org/wiki/Multiply-with-carry).

Constructor & Destructor Documentation

◆ MarsagliaRNG() [1/2]

MarsagliaRNG::MarsagliaRNG ( unsigned int  initial_z,
unsigned int  initial_w 
)

Creates a new Marsaglia RNG using the initial seeds.

Parameters
[in]initial_zOne of the random seed pairs
[in]initial_wOne of the random seed pairs.

◆ MarsagliaRNG() [2/2]

MarsagliaRNG::MarsagliaRNG ( )

Creates a new Marsaglia RNG using random initial seeds (which are read from the system clock).

Note that these will create variation between runs and between platforms.

Member Function Documentation

◆ generateNextInt32()

int32_t MarsagliaRNG::generateNextInt32 ( )
overridevirtual

Generates the next number as a signed 32-bit integer.

Implements SST::RNG::Random.

Referenced by generateNextInt64(), and generateNextUInt32().

◆ generateNextInt64()

int64_t MarsagliaRNG::generateNextInt64 ( )
overridevirtual

Generates the next number as a signed 64-bit integer.

Implements SST::RNG::Random.

References generateNextInt32().

Referenced by generateNextUInt64().

◆ generateNextUInt32()

uint32_t MarsagliaRNG::generateNextUInt32 ( )
overridevirtual

Generates the next random number as an unsigned 32-bit integer.

Implements SST::RNG::Random.

References generateNextInt32().

◆ generateNextUInt64()

uint64_t MarsagliaRNG::generateNextUInt64 ( )
overridevirtual

Generates the next random number as an unsigned 64-bit integer.

Implements SST::RNG::Random.

References generateNextInt64().

◆ nextUniform()

double MarsagliaRNG::nextUniform ( )
overridevirtual

Generates the next random number as a double in the range 0 to 1.

Implements SST::RNG::Random.

◆ restart()

void MarsagliaRNG::restart ( unsigned int  new_z,
unsigned int  new_w 
)

Restart the random number generator with new seeds.

Parameters
[in]new_zA new Z-seed
[in]new_wA new W-seed

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