mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::math::randomT< typeT, _ranengT, _randistT > Class Template Reference

template<class typeT, class _ranengT, class _randistT>
class mx::math::randomT< typeT, _ranengT, _randistT >

A random number type, which functions like any other arithmetic type.

Combines a random engine, and a random distribution. Using the type conversion operator randomT returns the next random deviate whenever it is referenced.

Example:

//This can also be done using the alias definition mx::math::normDistT.
randomT<double, std::mt19937_64, std::normal_distribution<double> > norm_distd;
norm_distd.seed(); //
double d1 = norm_distd; //get a normally distributed value
double d2 = norm_distd; //get the next normally distributed value
Test:

Verify compilation and basic operation of randomT with std::distributions [test doc]

Verify compilation and basic operation of randomT with the Laplace distribution [test doc]

Definition at line 60 of file randomT.hpp.

#include <math/randomT.hpp>

Public Types

typedef _randistT randistT
 Typedef for the distribution type. More...
 
typedef _ranengT ranengT
 Typedef for the engine type. More...
 

Public Member Functions

 randomT (bool doSeed=true)
 Constructor. More...
 
 operator typeT ()
 The conversion operator, returns the next value in the sequence, according to the distribution. More...
 
void seed (typename ranengT::result_type seedval)
 Set the seed of the random engine. More...
 
void seed ()
 Seed the random engine with a good value. More...
 

Public Attributes

_randistT distribution
 The random distribution. More...
 
ranengT engine
 The random engine. More...
 

Member Typedef Documentation

◆ randistT

template<class typeT , class _ranengT , class _randistT >
typedef _randistT mx::math::randomT< typeT, _ranengT, _randistT >::randistT

Typedef for the distribution type.

Definition at line 66 of file randomT.hpp.

◆ ranengT

template<class typeT , class _ranengT , class _randistT >
typedef _ranengT mx::math::randomT< typeT, _ranengT, _randistT >::ranengT

Typedef for the engine type.

Definition at line 69 of file randomT.hpp.

Constructor & Destructor Documentation

◆ randomT()

template<class typeT , class _ranengT , class _randistT >
mx::math::randomT< typeT, _ranengT, _randistT >::randomT ( bool  doSeed = true)
inline

Constructor.

By default this calls the seed method, which will use /dev/random to seed the generator on linux, and time(0) on other systems. Set to false to suppress seeding, and/or set a seed with seed(x).

Parameters
[in]doSeed[optional] if true then the seed method is called upon construction.

Definition at line 75 of file randomT.hpp.

References mx::math::randomT< typeT, _ranengT, _randistT >::seed().

Member Function Documentation

◆ operator typeT()

template<class typeT , class _ranengT , class _randistT >
mx::math::randomT< typeT, _ranengT, _randistT >::operator typeT ( )
inline

The conversion operator, returns the next value in the sequence, according to the distribution.

Definition at line 87 of file randomT.hpp.

◆ seed() [1/2]

template<class typeT , class _ranengT , class _randistT >
void mx::math::randomT< typeT, _ranengT, _randistT >::seed ( )
inline

Seed the random engine with a good value.

Calls mx::randomSeed to get the value. On linux this uses /dev/urandom. On other sytems, this uses time(0).

Definition at line 104 of file randomT.hpp.

References mx::math::randomSeed().

Referenced by mx::math::randomT< typeT, _ranengT, _randistT >::randomT().

◆ seed() [2/2]

template<class typeT , class _ranengT , class _randistT >
void mx::math::randomT< typeT, _ranengT, _randistT >::seed ( typename ranengT::result_type  seedval)
inline

Set the seed of the random engine.

Calls the engines seed member function.

Parameters
[in]seedvalthe argument to pass to ranengT::seed()

Definition at line 96 of file randomT.hpp.

References mx::math::randomT< typeT, _ranengT, _randistT >::engine.

Referenced by mx::AO::influenceFunctionsGaussian(), and SCENARIO().

Member Data Documentation

◆ distribution

template<class typeT , class _ranengT , class _randistT >
_randistT mx::math::randomT< typeT, _ranengT, _randistT >::distribution

The random distribution.

Definition at line 81 of file randomT.hpp.

Referenced by mx::math::randomT< int, std::mt19937_64, std::poisson_distribution< int > >::operator int().

◆ engine

template<class typeT , class _ranengT , class _randistT >
ranengT mx::math::randomT< typeT, _ranengT, _randistT >::engine

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