OMNeT++ Simulation Library  6.0.3
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 
30 inline uint32_t intrand(cRNG *rng, uint32_t r) {return rng->intRand(r);}
31 
35 inline double dblrand(cRNG *rng) {return rng->doubleRand();}
51 SIM_API double uniform(cRNG *rng, double a, double b);
52 
56 inline SimTime uniform(cRNG *rng, SimTime a, SimTime b) {return uniform(rng, a.dbl(), b.dbl());}
57 
65 SIM_API double exponential(cRNG *rng, double mean);
66 
70 inline SimTime exponential(cRNG *rng, SimTime mean) {return exponential(rng, mean.dbl());}
71 
80 SIM_API double normal(cRNG *rng, double mean, double stddev);
81 
85 inline SimTime normal(cRNG *rng, SimTime mean, SimTime stddev) {return normal(rng, mean.dbl(), stddev.dbl());}
86 
103 SIM_API double truncnormal(cRNG *rng, double mean, double stddev);
104 
108 inline SimTime truncnormal(cRNG *rng, SimTime mean, SimTime stddev) {return truncnormal(rng, mean.dbl(), stddev.dbl());}
109 
145 SIM_API double gamma_d(cRNG *rng, double alpha, double theta);
146 
159 SIM_API double beta(cRNG *rng, double alpha1, double alpha2);
160 
179 SIM_API double erlang_k(cRNG *rng, unsigned int k, double mean);
180 
198 SIM_API double chi_square(cRNG *rng, unsigned int k);
199 
211 SIM_API double student_t(cRNG *rng, unsigned int i);
212 
227 SIM_API double cauchy(cRNG *rng, double a, double b);
228 
238 SIM_API double triang(cRNG *rng, double a, double b, double c);
239 
251 inline double lognormal(cRNG *rng, double m, double w)
252 {
253  return exp(normal(rng, m, w));
254 }
255 
275 SIM_API double weibull(cRNG *rng, double a, double b);
276 
286 SIM_API double pareto_shifted(cRNG *rng, double a, double b, double c);
287 
304 SIM_API int intuniform(cRNG *rng, int a, int b);
305 
313 SIM_API int intuniformexcl(cRNG *rng, int a, int b);
314 
324 inline int bernoulli(cRNG *rng, double p)
325 {
326  double U = rng->doubleRand();
327  return (p > U) ? 1 : 0;
328 }
329 
342 SIM_API int binomial(cRNG *rng, int n, double p);
343 
356 SIM_API int geometric(cRNG *rng, double p);
357 
370 SIM_API int negbinomial(cRNG *rng, int n, double p);
371 
372 //
373 // hypergeometric() doesn't work yet
374 //
375 // /* *
376 // * Returns a random integer from the hypergeometric distribution with
377 // * parameters a,b and n.
378 // *
379 // * If you have a+b items (a items of type A and b items of type B)
380 // * and you draw n items from them without replication, this function
381 // * will return the number of type A items in the drawn set.
382 // *
383 // * Generation uses inverse transform due to Fishman (see Banks, page 165).
384 // *
385 // * @param a, b a,b>0
386 // * @param n 0<=n<=a+b
387 // * @param rng the underlying random number generator
388 // */
389 // SIM_API int hypergeometric(cRNG *rng, int a, int b, int n);
390 
406 SIM_API int poisson(cRNG *rng, double lambda);
407 
410 } // namespace omnetpp
411 
412 
413 #endif
414 
omnetpp::chi_square
SIM_API double chi_square(cRNG *rng, unsigned int k)
Returns a random variate from the chi-square distribution with k degrees of freedom.
omnetpp::gamma_d
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....
omnetpp::cRNG::intRand
virtual uint32_t intRand()=0
omnetpp::cauchy
SIM_API double cauchy(cRNG *rng, double a, double b)
Returns a random variate from the Cauchy distribution (also called Lorentzian distribution) with para...
omnetpp::truncnormal
SimTime truncnormal(cRNG *rng, SimTime mean, SimTime stddev)
SimTime version of truncnormal(cRNG*,double,double), for convenience.
Definition: distrib.h:108
omnetpp::geometric
SIM_API int geometric(cRNG *rng, double p)
Returns a random integer from the geometric distribution with parameter p, that is,...
omnetpp::uniform
SimTime uniform(cRNG *rng, SimTime a, SimTime b)
SimTime version of uniform(cRNG*,double,double), for convenience.
Definition: distrib.h:56
omnetpp::exponential
SimTime exponential(cRNG *rng, SimTime mean)
SimTime version of exponential(cRNG*,double), for convenience.
Definition: distrib.h:70
omnetpp::lognormal
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:251
omnetpp::normal
SimTime normal(cRNG *rng, SimTime mean, SimTime stddev)
SimTime version of normal(cRNG*,double,double), for convenience.
Definition: distrib.h:85
omnetpp::bernoulli
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:324
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::negbinomial
SIM_API int negbinomial(cRNG *rng, int n, double p)
Returns a random integer from the negative binomial distribution with parameters n and p,...
omnetpp::triang
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.
omnetpp::poisson
SIM_API int poisson(cRNG *rng, double lambda)
Returns a random integer from the Poisson distribution with parameter lambda, that is,...
omnetpp::intuniform
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...
omnetpp::cRNG
Abstract interface for random number generator classes.
Definition: crng.h:48
omnetpp::erlang_k
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.
omnetpp::intrand
uint32_t intrand(cRNG *rng, uint32_t r)
Produces a random integer in the range [0,r) using the RNG given with its index.
Definition: distrib.h:30
omnetpp::intuniformexcl
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].
omnetpp::pareto_shifted
SIM_API double pareto_shifted(cRNG *rng, double a, double b, double c)
Returns a random variate from the shifted generalized Pareto distribution.
omnetpp::SimTime::dbl
double dbl() const
Definition: simtime.h:307
omnetpp::student_t
SIM_API double student_t(cRNG *rng, unsigned int i)
Returns a random variate from the student-t distribution with i degrees of freedom....
omnetpp::cRNG::doubleRand
virtual double doubleRand()=0
omnetpp::beta
SIM_API double beta(cRNG *rng, double alpha1, double alpha2)
Returns a random variate from the beta distribution with parameters alpha1, alpha2.
omnetpp::dblrand
double dblrand(cRNG *rng)
Produces a random double in the range [0,1) using the RNG given with its index.
Definition: distrib.h:35
omnetpp::weibull
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...
omnetpp::binomial
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,...