CellModules
RandomManager.hpp
Go to the documentation of this file.
1
6#ifndef RANDOMMANAGER
7#define RANDOMMANAGER
8
9#include <mecacell/mecacell.h>
10#include <time.h>
11
12namespace Rand{
14 static std::uniform_real_distribution<double> probaGen(0.,1.);
15
21 static inline void initRandomSeed(int seed = clock()) {MecaCell::Config::globalRand().seed(seed);}
22
28 static inline double getProba(){return probaGen(MecaCell::Config::globalRand());}
29
37 static inline double getUniformDouble(double min, double max){
38 std::uniform_real_distribution<double> dist(min, max);
39 return dist(MecaCell::Config::globalRand());
40 }
41
49 static inline int getUniformInt(int min, int max){
50 std::uniform_int_distribution<int> dist(min, max);
51 return dist(MecaCell::Config::globalRand());
52 }
53
61 static inline double getNormalDouble(double mean, double var){
62 std::normal_distribution<double> dist(mean, var);
63 return dist(MecaCell::Config::globalRand());
64 }
65
72 static inline double getExponentialDouble(double lambda){
73 std::exponential_distribution<double> dist(lambda);
74 return dist(MecaCell::Config::globalRand());
75 }
76
84 static inline double getBoundedNormalDouble(double mean, double bound){
85 std::normal_distribution<double> dist(mean, bound/3.);
86 return std::min(dist(MecaCell::Config::globalRand()), bound);
87 }
88
95 static inline double getLinearDouble(std::vector<std::pair<double,double>> values){
97 for (auto it = std::make_move_iterator(values.begin()),
98 end = std::make_move_iterator(values.end()); it != end; ++it){
99 i.push_back(std::move(it->first));
100 w.push_back(std::move(it->second));
101 }
102 std::piecewise_linear_distribution<double> dist(i.begin(), i.end(), w.begin());
103 return dist(MecaCell::Config::globalRand());
104 }
105
113 static inline double getLogNormalDouble(double mu, double sigma2){
114 std::lognormal_distribution<double> dist(mu, sigma2);
115 return dist(MecaCell::Config::globalRand());
116 }
117
125 static inline double getLogNormalDoubleMeanStd(double mean, double std){
126 double sigma2 = log(1+(std * std)/(mean * mean));
127 double mu = log(mean) - 0.5*sigma2;
128 return getLogNormalDouble(mu, sigma2);
129 }
130}
131
132#endif
A simple vector class template.
Definition: std.hpp:290
void push_back(const T &value)
Adds an element to the end of the vector.
Definition: std.hpp:304
iterator begin()
Returns an iterator to the first element.
Definition: std.hpp:409
iterator end()
Returns an iterator to the last element.
Definition: std.hpp:418
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:1968
static std::uniform_real_distribution< double > probaGen(0., 1.)
@ignore
static double getLogNormalDouble(double mu, double sigma2)
Generates a random double in a log-normal distribution.
static double getProba()
Generates a random probability between 0 and 1.
static double getLogNormalDoubleMeanStd(double mean, double std)
Generates a random double in a log-normal distribution using mean and standard deviation.
static double getBoundedNormalDouble(double mean, double bound)
Generates a random double in a bounded normal distribution.
static int getUniformInt(int min, int max)
Generates a random integer in a uniform distribution.
static double getExponentialDouble(double lambda)
Generates a random double in an exponential distribution.
static void initRandomSeed(int seed=clock())
Initializes the random seed.
static double getUniformDouble(double min, double max)
Generates a random double in a uniform distribution.
static double getLinearDouble(std::vector< std::pair< double, double > > values)
Generates a random double in a piecewise linear distribution.
static double getNormalDouble(double mean, double var)
Generates a random double in a normal distribution.
Provides common mathematical functions and vector operations.
Definition: std.hpp:4
double log(double x)
Computes the natural logarithm of a number.
Definition: std.hpp:103
static random_engine_t & globalRand()
access to the static global random engine.This pseudo - random generator is* used in random 3D vector...
Definition: config.hpp:30