0.4.1
Loading...
Searching...
No Matches
NAV::RandomNumberGenerator Class Reference

Manages a thread which calls a specified function at a specified interval. More...

Public Member Functions

template<typename RealType = double>
double getRand_normalDist (RealType mean=0.0, RealType stddev=1.0)
 Gets a random number from a normal distribution.
 
template<typename IntType = int>
double getRand_uniformIntDist (IntType min=0, IntType max=std::numeric_limits< IntType >::max())
 Gets a random integer number from an uniform distribution.
 
template<typename RealType = double>
double getRand_uniformRealDist (RealType min=0.0, RealType max=1.0)
 Gets a random real number from an uniform distribution.
 
RandomNumberGeneratoroperator= (const RandomNumberGenerator &)=delete
 Copy assignment operator.
 
RandomNumberGeneratoroperator= (RandomNumberGenerator &&)=delete
 Move assignment operator.
 
 RandomNumberGenerator (bool useSeed=true)
 Default constructor.
 
 RandomNumberGenerator (const RandomNumberGenerator &)=delete
 Copy constructor.
 
 RandomNumberGenerator (RandomNumberGenerator &&)=delete
 Move constructor.
 
void resetSeed (size_t id=0)
 Reset the seed to the internal seed or the system time.
 
void resetSeedOnce (uint64_t userSeed)
 Reset the seed to the specified seed, but do not update the internal seed.
 
 ~RandomNumberGenerator ()=default
 Destructor.
 

Data Fields

uint64_t seed
 Seed for the random number generator.
 
bool useSeed
 Flag whether to use the seed instead of the system time.
 

Static Private Member Functions

static std::string hashSeed (const std::string &seed)
 Hash the given seed.
 

Private Attributes

std::mt19937_64 _generator
 Random number generator.
 

Detailed Description

Manages a thread which calls a specified function at a specified interval.

Definition at line 28 of file RandomNumberGenerator.hpp.

Constructor & Destructor Documentation

◆ RandomNumberGenerator() [1/3]

NAV::RandomNumberGenerator::RandomNumberGenerator ( bool useSeed = true)
inlineexplicit

Default constructor.

Definition at line 32 of file RandomNumberGenerator.hpp.

◆ RandomNumberGenerator() [2/3]

NAV::RandomNumberGenerator::RandomNumberGenerator ( const RandomNumberGenerator & )
delete

Copy constructor.

◆ RandomNumberGenerator() [3/3]

NAV::RandomNumberGenerator::RandomNumberGenerator ( RandomNumberGenerator && )
delete

Move constructor.

◆ ~RandomNumberGenerator()

NAV::RandomNumberGenerator::~RandomNumberGenerator ( )
default

Destructor.

Member Function Documentation

◆ getRand_normalDist()

template<typename RealType = double>
double NAV::RandomNumberGenerator::getRand_normalDist ( RealType mean = 0.0,
RealType stddev = 1.0 )
inline

Gets a random number from a normal distribution.

Template Parameters
RealTypeThe result type generated by the generator. The effect is undefined if this is not one of float, double, or long double
Parameters
meanThe μ distribution parameter (mean)
stddevThe σ distribution parameter (standard deviation)
Returns
Random number

Definition at line 91 of file RandomNumberGenerator.hpp.

◆ getRand_uniformIntDist()

template<typename IntType = int>
double NAV::RandomNumberGenerator::getRand_uniformIntDist ( IntType min = 0,
IntType max = std::numeric_limits<IntType>::max() )
inline

Gets a random integer number from an uniform distribution.

Template Parameters
IntTypeThe result type generated by the generator. The effect is undefined if this is not one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long.
Parameters
minMinimum value
maxMaximum value
Returns
Random number

Definition at line 69 of file RandomNumberGenerator.hpp.

◆ getRand_uniformRealDist()

template<typename RealType = double>
double NAV::RandomNumberGenerator::getRand_uniformRealDist ( RealType min = 0.0,
RealType max = 1.0 )
inline

Gets a random real number from an uniform distribution.

Template Parameters
RealTypeThe result type generated by the generator. The effect is undefined if this is not one of float, double, or long double
Parameters
minMinimum value
maxMaximum value
Returns
Random number

Definition at line 80 of file RandomNumberGenerator.hpp.

◆ hashSeed()

static std::string NAV::RandomNumberGenerator::hashSeed ( const std::string & seed)
inlinestaticprivate

Hash the given seed.

Parameters
seedSeed
Returns
Hashed seed

Definition at line 103 of file RandomNumberGenerator.hpp.

◆ operator=() [1/2]

RandomNumberGenerator & NAV::RandomNumberGenerator::operator= ( const RandomNumberGenerator & )
delete

Copy assignment operator.

◆ operator=() [2/2]

RandomNumberGenerator & NAV::RandomNumberGenerator::operator= ( RandomNumberGenerator && )
delete

Move assignment operator.

◆ resetSeed()

void NAV::RandomNumberGenerator::resetSeed ( size_t id = 0)
inline

Reset the seed to the internal seed or the system time.

Parameters
idSome id used to make a unique hash when using the system time to set the seed

Definition at line 46 of file RandomNumberGenerator.hpp.

◆ resetSeedOnce()

void NAV::RandomNumberGenerator::resetSeedOnce ( uint64_t userSeed)
inline

Reset the seed to the specified seed, but do not update the internal seed.

Parameters
[in]userSeedSeed to use once

Definition at line 56 of file RandomNumberGenerator.hpp.

Field Documentation

◆ _generator

std::mt19937_64 NAV::RandomNumberGenerator::_generator
private

Random number generator.

Definition at line 115 of file RandomNumberGenerator.hpp.

◆ seed

uint64_t NAV::RandomNumberGenerator::seed

Seed for the random number generator.

Definition at line 97 of file RandomNumberGenerator.hpp.

◆ useSeed

bool NAV::RandomNumberGenerator::useSeed

Flag whether to use the seed instead of the system time.

Definition at line 96 of file RandomNumberGenerator.hpp.


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