OMNeT++ Simulation Library  5.6.1
distrib.h
1 //==========================================================================
2 // DISTRIB.H
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 // Authors: Werner Sandmann (ws), Kay Michael Masslow (kmm), Kyeong Soo (Joseph) Kim (jk)
9 // Documentation, maintenance: Andras Varga
10 
11 #ifndef __OMNETPP_DISTRIB_H
12 #define __OMNETPP_DISTRIB_H
13 
14 #include "simkerneldefs.h"
15 #include "crng.h"
16 #include "simtime.h"
17 
18 namespace omnetpp {
19 
20 //TODO @group etc
24 inline unsigned long intrand(cRNG *rng, long r) {return rng->intRand(r);}
25 
29 inline double dblrand(cRNG *rng) {return rng->doubleRand();}
30 
37 
44 SIM_API double uniform(cRNG *rng, double a, double b);
45 
49 inline SimTime uniform(cRNG *rng, SimTime a, SimTime b) {return uniform(rng, a.dbl(), b.dbl());}
50 
58 SIM_API double exponential(cRNG *rng, double mean);
59 
63 inline SimTime exponential(cRNG *rng, SimTime mean) {return exponential(rng, mean.dbl());}
64 
73 SIM_API double normal(cRNG *rng, double mean, double stddev);
74 
78 inline SimTime normal(cRNG *rng, SimTime mean, SimTime stddev) {return normal(rng, mean.dbl(), stddev.dbl());}
79 
96 SIM_API double truncnormal(cRNG *rng, double mean, double stddev);
97 
101 inline SimTime truncnormal(cRNG *rng, SimTime mean, SimTime stddev) {return truncnormal(rng, mean.dbl(), stddev.dbl());}
102 
138 SIM_API double gamma_d(cRNG *rng, double alpha, double theta);
139 
152 SIM_API double beta(cRNG *rng, double alpha1, double alpha2);
153 
172 SIM_API double erlang_k(cRNG *rng, unsigned int k, double mean);
173 
191 SIM_API double chi_square(cRNG *rng, unsigned int k);
192 
204 SIM_API double student_t(cRNG *rng, unsigned int i);
205 
220 SIM_API double cauchy(cRNG *rng, double a, double b);
221 
231 SIM_API double triang(cRNG *rng, double a, double b, double c);
232 
244 inline double lognormal(cRNG *rng, double m, double w)
245 {
246  return exp(normal(rng, m, w));
247 }
248 
268 SIM_API double weibull(cRNG *rng, double a, double b);
269 
279 SIM_API double pareto_shifted(cRNG *rng, double a, double b, double c);
280 
282 
289 
297 SIM_API int intuniform(cRNG *rng, int a, int b);
298 
306 SIM_API int intuniformexcl(cRNG *rng, int a, int b);
307 
317 inline int bernoulli(cRNG *rng, double p)
318 {
319  double U = rng->doubleRand();
320  return (p > U) ? 1 : 0;
321 }
322 
335 SIM_API int binomial(cRNG *rng, int n, double p);
336 
349 SIM_API int geometric(cRNG *rng, double p);
350 
363 SIM_API int negbinomial(cRNG *rng, int n, double p);
364 
365 //
366 // hypergeometric() doesn't work yet
367 //
368 // /* *
369 // * Returns a random integer from the hypergeometric distribution with
370 // * parameters a,b and n.
371 // *
372 // * If you have a+b items (a items of type A and b items of type B)
373 // * and you draw n items from them without replication, this function
374 // * will return the number of type A items in the drawn set.
375 // *
376 // * Generation uses inverse transform due to Fishman (see Banks, page 165).
377 // *
378 // * @param a, b a,b>0
379 // * @param n 0<=n<=a+b
380 // * @param rng the underlying random number generator
381 // */
382 // SIM_API int hypergeometric(cRNG *rng, int a, int b, int n);
383 
399 SIM_API int poisson(cRNG *rng, double lambda);
400 
402 
403 } // namespace omnetpp
404 
405 
406 #endif
407 
SIM_API double triang(cRNG *rng, double a, double b, double c)
Returns a random variate from the triangular distribution with parameters a <= b <= c...
SIM_API double cauchy(cRNG *rng, double a, double b)
Returns a random variate from the Cauchy distribution (also called Lorentzian distribution) with para...
SIM_API int intuniformexcl(cRNG *rng, int a, int b)
Returns a random integer with uniform distribution over [a,b), that is, from [a,b-1].
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
SIM_API double pareto_shifted(cRNG *rng, double a, double b, double c)
Returns a random variate from the shifted generalized Pareto distribution.
SIM_API int binomial(cRNG *rng, int n, double p)
Returns a random integer from the binomial distribution with parameters n and p, that is...
SIM_API double student_t(cRNG *rng, unsigned int i)
Returns a random variate from the student-t distribution with i degrees of freedom. If Y1 has a normal distribution and Y2 has a chi-square distribution with k degrees of freedom then X = Y1 / sqrt(Y2/k) has a student-t distribution with k degrees of freedom.
SIM_API double chi_square(cRNG *rng, unsigned int k)
Returns a random variate from the chi-square distribution with k degrees of freedom.
Abstract interface for random number generator classes.
Definition: crng.h:49
SIM_API int intuniform(cRNG *rng, int a, int b)
Returns a random integer with uniform distribution in the range [a,b], inclusive. (Note that the func...
SIM_API int geometric(cRNG *rng, double p)
Returns a random integer from the geometric distribution with parameter p, that is, the number of independent trials with probability p until the first success.
SIM_API int negbinomial(cRNG *rng, int n, double p)
Returns a random integer from the negative binomial distribution with parameters n and p...
SIM_API int poisson(cRNG *rng, double lambda)
Returns a random integer from the Poisson distribution with parameter lambda, that is...
SIM_API double beta(cRNG *rng, double alpha1, double alpha2)
Returns a random variate from the beta distribution with parameters alpha1, alpha2.
double dbl() const
Definition: simtime.h:301
int bernoulli(cRNG *rng, double p)
Returns the result of a Bernoulli trial with probability p, that is, 1 with probability p and 0 with ...
Definition: distrib.h:317
SIM_API double weibull(cRNG *rng, double a, double b)
Returns a random variate from the Weibull distribution with parameters a, b > 0, where a is the "scal...
SimTime truncnormal(cRNG *rng, SimTime mean, SimTime stddev)
SimTime version of truncnormal(cRNG*,double,double), for convenience.
Definition: distrib.h:101
SIM_API double gamma_d(cRNG *rng, double alpha, double theta)
Returns a random variate from the gamma distribution with parameters alpha>0, theta>0. Alpha is known as the "shape" parameter, and theta as the "scale" parameter.
virtual double doubleRand()=0
double lognormal(cRNG *rng, double m, double w)
Returns a random variate from the lognormal distribution with "scale" parameter m and "shape" paramet...
Definition: distrib.h:244
Definition: cabstracthistogram.h:21
SIM_API double erlang_k(cRNG *rng, unsigned int k, double mean)
Returns a random variate from the Erlang distribution with k phases and mean mean.
SimTime uniform(cRNG *rng, SimTime a, SimTime b)
SimTime version of uniform(cRNG*,double,double), for convenience.
Definition: distrib.h:49
SimTime exponential(cRNG *rng, SimTime mean)
SimTime version of exponential(cRNG*,double), for convenience.
Definition: distrib.h:63
SimTime normal(cRNG *rng, SimTime mean, SimTime stddev)
SimTime version of normal(cRNG*,double,double), for convenience.
Definition: distrib.h:78