Helios++
Helios software for LiDAR simulations
RandomnessGenerator< RealType > Class Template Reference

Class to generate random numbers. More...

#include <RandomnessGenerator.h>

Collaboration diagram for RandomnessGenerator< RealType >:

Public Member Functions

 RandomnessGenerator ()
 Creates a RandomnessGenerator which will use an automatically computed seed.
 
 RandomnessGenerator (double seed)
 Creates a RandomnessGenerator which will use a double seed. More...
 
 RandomnessGenerator (float seed)
 Like RandomnessGenerator(double) constructor, the float is casted to a double. More...
 
 RandomnessGenerator (long seed)
 Creates a RandomnessGenerator which will use a long seed. More...
 
 RandomnessGenerator (int seed)
 Like RandomnessGenerator(long) constructor, the integer is casted to a long. More...
 
 RandomnessGenerator (std::string const &seedstr)
 Creates a RandomnessGenerator by parsing the string to automatically extract the seed and define the mode. More...
 
 RandomnessGenerator (RandomnessGenerator const &rg)
 Copy constructor for RandomnessGenerator. More...
 
 RandomnessGenerator (RandomnessGenerator &&rg) noexcept
 Move constructor for RandomnessGenerator. More...
 
RandomnessGeneratoroperator= (RandomnessGenerator const &rg)
 Copy assignment operator. More...
 
RandomnessGeneratoroperator= (RandomnessGenerator &&rg)
 Move assignment operator. More...
 
void swap (RandomnessGenerator &rgA, RandomnessGenerator &rgB)
 Swap two RandomnessGenerator. More...
 
void computeUniformRealDistribution (RealType lowerBound, RealType upperBound)
 Compute a uniform real distribution using the specified real data type. More...
 
RealType uniformRealDistributionNext ()
 Obtain the next value in the computed uniform real distribution. More...
 
void computeNormalDistribution (RealType mean, RealType stdev)
 Compute a normal distribution using the specified real data type. More...
 
RealType normalDistributionNext ()
 Obtain the next value in the computed normal distribution. More...
 

Protected Member Functions

double getDoubleSeed ()
 Obtain the seed in double format. This getter is expected to be used with mode FIXED_SEED_DOUBLE. More...
 
long getLongSeed ()
 Obtain the seed in long format. This getter is expected to be used with mode FIXED_SEED_LONG. More...
 

Protected Attributes

std::string mode
 RandomnessGenerator mode. More...
 
double doubleSeed = 0
 Double seed for randomness.
 
long longSeed = 0
 Long seed for randomness.
 
std::unique_ptr< boost::mt19937 > urdGen = nullptr
 Uniform Real Distribution Generator.
 
std::unique_ptr< boost::random::uniform_real_distribution< RealType > > urd = nullptr
 Uniform Real Distribution.
 
std::unique_ptr< boost::mt19937 > ndGen = nullptr
 Normal Distribution Generator.
 
std::unique_ptr< boost::normal_distribution< RealType > > nd = nullptr
 Normal Distribution.
 

Detailed Description

template<typename RealType>
class RandomnessGenerator< RealType >

Class to generate random numbers.

Author
Alberto M. Esmoris Pena
Version
1.0
Template Parameters
RealTypeType of the generated real random numbers. For instance double or float.

Constructor & Destructor Documentation

◆ RandomnessGenerator() [1/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( double  seed)
inlineexplicit

Creates a RandomnessGenerator which will use a double seed.

Parameters
seedThe double seed to be used

◆ RandomnessGenerator() [2/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( float  seed)
inlineexplicit

Like RandomnessGenerator(double) constructor, the float is casted to a double.

See also
RandomnessGenerator::RandomnessGenerator(double)

◆ RandomnessGenerator() [3/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( long  seed)
inlineexplicit

Creates a RandomnessGenerator which will use a long seed.

Parameters
seedThe long seed to be used

◆ RandomnessGenerator() [4/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( int  seed)
inlineexplicit

Like RandomnessGenerator(long) constructor, the integer is casted to a long.

See also
RandomnessGenerator::RandomnessGenerator(double)

◆ RandomnessGenerator() [5/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( std::string const &  seedstr)
explicit

Creates a RandomnessGenerator by parsing the string to automatically extract the seed and define the mode.

Parameters
seedstrString containing the seed. It can be a long integer, a double decimal or a timestamp string in "YYYY-mm-DD HH:MM:SS" format.
NOTICE timestamp CANNOT specify a date before 1970-01-01 00:00:00. It would lead to undefined behaviors.

◆ RandomnessGenerator() [6/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( RandomnessGenerator< RealType > const &  rg)

Copy constructor for RandomnessGenerator.

Internal components will be copied preserving their status. So, when obtaining the next value from a distribution, it will be computed starting at the last considered value for the copied randomness generator.

Parameters
rgRandomnessGenerator to be copied

◆ RandomnessGenerator() [7/7]

template<typename RealType >
RandomnessGenerator< RealType >::RandomnessGenerator ( RandomnessGenerator< RealType > &&  rg)
noexcept

Move constructor for RandomnessGenerator.

Parameters
rgRandomnessGenerator to be moved

Member Function Documentation

◆ computeNormalDistribution()

template<typename RealType >
void RandomnessGenerator< RealType >::computeNormalDistribution ( RealType  mean,
RealType  stdev 
)

Compute a normal distribution using the specified real data type.

Parameters
meanThe mean value for the normal distribution
stdevThe standard deviation value for the normal distribution

◆ computeUniformRealDistribution()

template<typename RealType >
void RandomnessGenerator< RealType >::computeUniformRealDistribution ( RealType  lowerBound,
RealType  upperBound 
)

Compute a uniform real distribution using the specified real data type.

Parameters
lowerBoundNo less than lower bound values are allowed
upperBoundNo greater than upper bound values are allowed
Returns
Uniform real distribution satisfying specified bounds

◆ getDoubleSeed()

template<typename RealType >
double RandomnessGenerator< RealType >::getDoubleSeed ( )
inlineprotected

Obtain the seed in double format. This getter is expected to be used with mode FIXED_SEED_DOUBLE.

Returns
Seed in double format

◆ getLongSeed()

template<typename RealType >
long RandomnessGenerator< RealType >::getLongSeed ( )
inlineprotected

Obtain the seed in long format. This getter is expected to be used with mode FIXED_SEED_LONG.

Returns
Seed in long format

◆ normalDistributionNext()

template<typename RealType >
RealType RandomnessGenerator< RealType >::normalDistributionNext

Obtain the next value in the computed normal distribution.

If no normal distribution has been computed, then it is computed before obtaining the first element in the distribution. When normal distribution is computed by this method, its mean is 0 and its standard deviation is 1

Returns
Next real number in the normal distribution

◆ operator=() [1/2]

template<typename RealType >
RandomnessGenerator< RealType > & RandomnessGenerator< RealType >::operator= ( RandomnessGenerator< RealType > &&  rg)

Move assignment operator.

Parameters
rgRandomnessGenerator to be moved
Returns
Reference to moved RandomnessGenerator

◆ operator=() [2/2]

template<typename RealType >
RandomnessGenerator< RealType > & RandomnessGenerator< RealType >::operator= ( RandomnessGenerator< RealType > const &  rg)

Copy assignment operator.

Parameters
rgRandomnessGenerator to be copied
Returns
Reference to copied RandomnessGenerator

◆ swap()

template<typename RealType >
void RandomnessGenerator< RealType >::swap ( RandomnessGenerator< RealType > &  rgA,
RandomnessGenerator< RealType > &  rgB 
)

Swap two RandomnessGenerator.

Parameters
rgARandomnessGenerator to be swapped with rgB
rgBRandomnessGenerator to be swapped with rgA

◆ uniformRealDistributionNext()

template<typename RealType >
RealType RandomnessGenerator< RealType >::uniformRealDistributionNext

Obtain the next value in the computed uniform real distribution.

If no uniform real distribution has been computed, then it is computed before obtaining the first element in the distribution. When uniform real distribution is computed by this method, it is bounded inside interval [0, 1]

Returns
Next real number in the uniform real distribution

Member Data Documentation

◆ mode

template<typename RealType >
std::string RandomnessGenerator< RealType >::mode
protected

RandomnessGenerator mode.

Specify the mode for the RandomnessGenerator.
Available modes are:
AUTO_SEED : Use and automatically computed seed
FIXED_SEED_DOUBLE : Use a fixed double decimal seed.
FIXED_SEED_LONG : Use a fixed long integer seed.<br/


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