roadrunner  2.6.0
Fast simulator for SBML models
Random.h
1 /*
2  * LLVMRandom.h
3  *
4  * Created on: Sep 23, 2014
5  * Author: andy
6  */
7 
8 #ifndef _RRLLVM_RANDOM_H_
9 #define _RRLLVM_RANDOM_H_
10 
11 #include "tr1proxy/rr_random.h" // rr proxy to <random>
12 #include <stdint.h>
13 
14 namespace rrllvm {
15 
21  class Random {
22  public:
28 
33  Random(const Random& other);
34 
39  Random& operator=(const Random& rhs);
40 
46  Random();
47 
48  ~Random();
49 
54  double operator()();
55 
59  int getMaxTries() const;
60 
64  void setMaxTries(int maxTries);
65 
66 #ifdef CXX11_RANDOM
70  static constexpr unsigned long long min() { return 0; };
71 
75  static constexpr unsigned long long max() { return 1; };
76 #else
77 
81  double min() { return 0.0; };
82 
86  double max() { return 1.0; };
87 #endif
88 
94  void setRandomSeed(int64_t);
95 
100  int64_t getRandomSeed();
101 
105  cxx11_ns::mt19937 engine;
106 
107  private:
108  // seed that was used to seed the engine.
109  int64_t randomSeed;
110  // internal distribution used to generate reals between 0.0 and 1.0
111 
112 #ifdef CXX11_RANDOM
113  cxx11_ns::uniform_real_distribution<double> normalized_uniform_dist;
114 #else
115  cxx11_ns::uniform_real<double> normalized_uniform_dist;
116 #endif
117 
121  int mMaxTries;
122 
123  };
124 
125  double distrib_uniform(Random* random, double _min, double _max);
126  double distrib_normal(Random* random, double mu, double sigma);
127  double distrib_normal_four(Random* random, double mu, double sigma, double _min, double _max);
128  double distrib_bernoulli(Random* random, double prob);
129  double distrib_binomial(Random* random, double nTrials, double probabilityOfSuccess);
130  double distrib_binomial_four(Random* random, double nTrials, double probabilityOfSuccess, double _min, double _max);
131  double distrib_cauchy(Random* random, double location, double scale);
132  double distrib_cauchy_one(Random* random, double scale);
133  double distrib_cauchy_four(Random* random, double location, double scale, double _min, double _max);
134  double distrib_chisquare(Random* random, double degreesOfFreedom);
135  double distrib_chisquare_three(Random* random, double degreesOfFreedom, double _min, double _max);
136  double distrib_exponential(Random* random, double lambda);
137  double distrib_exponential_three(Random* random, double lambda, double _min, double _max);
138  double distrib_gamma(Random* random, double shape, double scale);
139  double distrib_gamma_four(Random* random, double shape, double scale, double _min, double _max);
140  double distrib_laplace(Random* random, double location, double scale);
141  double distrib_laplace_one(Random* random, double scale);
142  double distrib_laplace_four(Random* random, double location, double scale, double _min, double _max);
143  double distrib_lognormal(Random* random, double mu, double sigma);
144  double distrib_lognormal_four(Random* random, double mu, double sigma, double _min, double _max);
145  double distrib_poisson(Random* random, double lambda);
146  double distrib_poisson_three(Random* random, double lambda, double _min, double _max);
147  double distrib_rayleigh(Random* random, double scale);
148  double distrib_rayleigh_three(Random* random, double scale, double _min, double _max);
149 
150 
151 } /* namespace rrllvm */
152 
153 #endif /* _RRLLVM_RANDOM_H_ */
Definition: rrRandom.h:14
All LLVM code generating objects basically need at a minimum three things to operate:
Definition: ModelGeneratorContext.h:95
cxx11_ns::mt19937 engine
RNG engine.
Definition: Random.h:105
Random(class ModelGeneratorContext &ctx)
creates a new Random object and adds the distrib as global mappings to the execution engine.
double max()
max random number.
Definition: Random.h:86
double min()
min random number.
Definition: Random.h:81
double operator()()
return a normalized random number between 0 and 1 using the RNG engine.
Definition: Random.cpp:563
Random()
default ctor, this obviously does not add any mappings to a ModelGeneratorContext.
Random & operator=(const Random &rhs)
assignment operator, copies the fields from the other object, but does not re-intialize them.
Definition: Random.cpp:91
int getMaxTries() const
Returns the maximum number of tries to find a value inside a truncated range.
Definition: Random.cpp:570
void setMaxTries(int maxTries)
Sets the maximum number of tries to find a value inside a truncated range.
Definition: Random.cpp:575