Class for management of random. It includes distribution utility functions.
Sources:
Example : declaring an instance
Example : initializing with a custom seed
Example : initializing with a random seed
Example : getting a random generated number using normal distribution
int randomizedIntValue = Rng.
rnorm(2, 10);
Example : getting randomized value using Bernoulli distribution
bool randomizedBoolValue = Rng.
bernoulli(0.7);
#include <tools/RandomNumberGenerator.hpp>
|
| | RandomNumberGenerator () |
| |
| | ~RandomNumberGenerator () |
| |
| void | init (long int CustomSeed=-1) |
| |
| uint64_t | getSelectedSeed () const |
| |
| template<typename T > |
| std::vector< T > | rlnorm (size_t N, double Mean, double Sd) |
| | Log normal distribution. More...
|
| |
| template<typename T > |
| std::vector< T > | rnorm (size_t N, double Mean, double Sd) |
| | Normal distribution. More...
|
| |
| template<typename T > |
| std::vector< T > | runif (size_t N, T V1, T V2) |
| | Uniform distribution. More...
|
| |
| template<typename T > |
| std::vector< T > | irunif (size_t N, T V1, T V2) |
| | Uniform distribution. More...
|
| |
| template<typename T > |
| T | rlnorm (double Mean, double Sd) |
| | Log normal distribution. More...
|
| |
| template<typename T > |
| T | rnorm (double Mean, double Sd) |
| | Normal distribution. More...
|
| |
| template<typename T > |
| T | runif (T V1, T V2) |
| | Real uniform distribution. More...
|
| |
| template<typename T > |
| T | irunif (T V1, T V2) |
| | Integer uniform distribution. More...
|
| |
| bool | bernoulli (double Probability) |
| | Bernoulli distribution. More...
|
| |
◆ RandomNumberGenerator()
| openfluid::tools::RandomNumberGenerator::RandomNumberGenerator |
( |
| ) |
|
◆ ~RandomNumberGenerator()
| openfluid::tools::RandomNumberGenerator::~RandomNumberGenerator |
( |
| ) |
|
|
inline |
◆ bernoulli()
| bool openfluid::tools::RandomNumberGenerator::bernoulli |
( |
double |
Probability | ) |
|
|
inline |
Bernoulli distribution.
- Parameters
-
| Probability | probability of success |
- Returns
- Randomized value using bernoulli distribution
◆ displaySeedInfo()
| virtual void openfluid::tools::RandomNumberGenerator::displaySeedInfo |
( |
| ) |
|
|
protectedvirtual |
◆ getGenerator()
| std::mt19937_64& openfluid::tools::RandomNumberGenerator::getGenerator |
( |
| ) |
|
|
protected |
◆ getSelectedSeed()
| uint64_t openfluid::tools::RandomNumberGenerator::getSelectedSeed |
( |
| ) |
const |
Returns the seed
- Returns
- an uint64_t
◆ init()
| void openfluid::tools::RandomNumberGenerator::init |
( |
long int |
CustomSeed = -1 | ) |
|
Set a seed for the generator
- Parameters
-
| [in] | CustomSeed | The seed to set. If negative, random seed will be used |
◆ irunif() [1/2]
template<typename T >
| std::vector<T> openfluid::tools::RandomNumberGenerator::irunif |
( |
size_t |
N, |
|
|
T |
V1, |
|
|
T |
V2 |
|
) |
| |
|
inline |
Uniform distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| N | number of values to generate with distribution |
| V1 | min value for distribution |
| V2 | max value for distribution |
- Returns
- std::vector<T> vector with N randomized values using integer uniform distribution
◆ irunif() [2/2]
template<typename T >
| T openfluid::tools::RandomNumberGenerator::irunif |
( |
T |
V1, |
|
|
T |
V2 |
|
) |
| |
|
inline |
Integer uniform distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| V1 | min value for distribution |
| V2 | max value for distribution |
- Returns
- Randomized value using integer uniform distribution
◆ rlnorm() [1/2]
template<typename T >
| T openfluid::tools::RandomNumberGenerator::rlnorm |
( |
double |
Mean, |
|
|
double |
Sd |
|
) |
| |
|
inline |
Log normal distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| Mean | mean for log normal distribution |
| Sd | standard deviation for log normal distribution |
- Returns
- Randomized value using log normal distribution
◆ rlnorm() [2/2]
template<typename T >
| std::vector<T> openfluid::tools::RandomNumberGenerator::rlnorm |
( |
size_t |
N, |
|
|
double |
Mean, |
|
|
double |
Sd |
|
) |
| |
|
inline |
Log normal distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| N | number of values to generate with distribution |
| Mean | mean for log normal distribution |
| Sd | standard deviation for log normal distribution |
- Returns
- std::vector<T> vector with N randomized values using log normal distribution
◆ rnorm() [1/2]
template<typename T >
| T openfluid::tools::RandomNumberGenerator::rnorm |
( |
double |
Mean, |
|
|
double |
Sd |
|
) |
| |
|
inline |
Normal distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| Mean | mean for normal distribution |
| Sd | standard deviation for normal distribution |
- Returns
- Randomized value using normal distribution
◆ rnorm() [2/2]
template<typename T >
| std::vector<T> openfluid::tools::RandomNumberGenerator::rnorm |
( |
size_t |
N, |
|
|
double |
Mean, |
|
|
double |
Sd |
|
) |
| |
|
inline |
Normal distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| N | number of values to generate with distribution |
| Mean | mean for normal distribution |
| Sd | standard deviation for normal distribution |
- Returns
- std::vector<T> vector with N randomized values using normal distribution
◆ runif() [1/2]
template<typename T >
| std::vector<T> openfluid::tools::RandomNumberGenerator::runif |
( |
size_t |
N, |
|
|
T |
V1, |
|
|
T |
V2 |
|
) |
| |
|
inline |
Uniform distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| N | number of values to generate with distribution |
| V1 | min value for distribution |
| V2 | max value for distribution |
- Returns
- std::vector<T> vector with N randomized values using real uniform distribution
◆ runif() [2/2]
template<typename T >
| T openfluid::tools::RandomNumberGenerator::runif |
( |
T |
V1, |
|
|
T |
V2 |
|
) |
| |
|
inline |
Real uniform distribution.
- Template Parameters
-
| T | type of value for distribution |
- Parameters
-
| V1 | min value for distribution |
| V2 | max value for distribution |
- Returns
- Randomized value using real uniform distribution
◆ m_DisplayNameInfo
| const std::string openfluid::tools::RandomNumberGenerator::m_DisplayNameInfo |
|
protected |
A string to display the seed in logs as "Seed: ${m_SelectedSeed}"
◆ m_DisplaySeed
| bool openfluid::tools::RandomNumberGenerator::m_DisplaySeed |
|
protected |
A boolean to check if we need to display the seed in logs
◆ m_Generator
| std::mt19937_64 openfluid::tools::RandomNumberGenerator::m_Generator |
|
protected |
The Mersenne Twister generator
◆ m_SelectedSeed
| uint64_t openfluid::tools::RandomNumberGenerator::m_SelectedSeed |
|
protected |
The documentation for this class was generated from the following file: