Stormancer::RandomNumberGenerator Class Reference

A pseudo-random number generator. Uses the C++11 default random engine. More...

#include <RandomNumberGenerator.h>

Public Member Functions

 RandomNumberGenerator ()
 Construct a RandomNumberGenerator, seeding its random engine with a random number from the system's random device. More...
 
int getInt (int lowerBound, int upperBound)
 Get a random integer between lowerBound (inclusive) and upperBound (exclusive). More...
 
int getInt ()
 Get a random integer between 0 and MAX_INT. More...
 

Static Public Member Functions

static RandomNumberGeneratorgetThreadLocal ()
 Get a static thread-local RandomNumberGenerator instance. More...
 

Detailed Description

A pseudo-random number generator. Uses the C++11 default random engine.

Instances of this class must not be shared between threads. The recommended use is to call getThreadLocal().getInt() when you need a random number.

Constructor & Destructor Documentation

◆ RandomNumberGenerator()

Stormancer::RandomNumberGenerator::RandomNumberGenerator ( )

Construct a RandomNumberGenerator, seeding its random engine with a random number from the system's random device.

Member Function Documentation

◆ getInt() [1/2]

int Stormancer::RandomNumberGenerator::getInt ( )

Get a random integer between 0 and MAX_INT.

Returns
A random integer in the range [0, MAX_INT).

◆ getInt() [2/2]

int Stormancer::RandomNumberGenerator::getInt ( int  lowerBound,
int  upperBound 
)

Get a random integer between lowerBound (inclusive) and upperBound (exclusive).

Parameters
lowerBoundThe minumum value, inclusive.
upperBoundThe maximum value, exclusive.
Returns
A random integer in the range [lowerBound, upperBound).

◆ getThreadLocal()

static RandomNumberGenerator& Stormancer::RandomNumberGenerator::getThreadLocal ( )
static

Get a static thread-local RandomNumberGenerator instance.

Returns
A reference to a static thread-local RandomNumberGenerator.

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