16#ifndef __OMNETPP_CRANDOM_H
17#define __OMNETPP_CRANDOM_H
20#include "cownedobject.h"
31class SIM_API cRandom :
public cOwnedObject
40 cRandom(
const char *name=
nullptr,
cRNG *rng=
nullptr);
62 virtual double draw()
const = 0;
75class SIM_API cUniform :
public cRandom
81 void copy(
const cUniform& other);
85 cUniform(
cRNG *rng,
double a,
double b) : cRandom(rng), a(a), b(b) {}
86 cUniform(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double a=0,
double b=1) : cRandom(name, rng), a(a), b(b) {}
87 cUniform(
const cUniform& other) : cRandom(other) {copy(other);}
88 virtual cUniform *
dup()
const override {
return new cUniform(*
this);}
90 virtual std::string
str()
const override;
95 void setA(
double a) {this->a = a;}
96 double getA()
const {
return a;}
97 void setB(
double b) {this->b = b;}
98 double getB()
const {
return b;}
103 virtual double draw()
const override;
115class SIM_API cExponential :
public cRandom
120 void copy(
const cExponential& other);
124 cExponential(
cRNG *rng,
double mean) : cRandom(rng), mean(mean) {}
125 cExponential(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double mean=1) : cRandom(rng), mean(mean) {}
126 cExponential(
const cExponential& other) : cRandom(other) {copy(other);}
127 virtual cExponential *
dup()
const override {
return new cExponential(*
this);}
129 virtual std::string
str()
const override;
134 void setMean(
double mean) {this->mean = mean;}
135 double getMean()
const {
return mean;}
140 virtual double draw()
const override;
153class SIM_API cNormal :
public cRandom
159 void copy(
const cNormal& other);
163 cNormal(
cRNG *rng,
double mean,
double stddev) : cRandom(rng), mean(mean), stddev(stddev) {}
164 cNormal(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double mean=0,
double stddev=1) : cRandom(rng), mean(mean), stddev(stddev) {}
165 cNormal(
const cNormal& other) : cRandom(other) {copy(other);}
166 virtual cNormal *
dup()
const override {
return new cNormal(*
this);}
168 virtual std::string
str()
const override;
173 void setMean(
double mean) {this->mean = mean;}
174 double getMean()
const {
return mean;}
175 void setStddev(
double stddev) {this->stddev = stddev;}
176 double getStddev()
const {
return stddev;}
181 virtual double draw()
const override;
194class SIM_API cTruncNormal :
public cRandom
200 void copy(
const cTruncNormal& other);
204 cTruncNormal(
cRNG *rng,
double mean,
double stddev) : cRandom(rng), mean(mean), stddev(stddev) {}
205 cTruncNormal(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double mean=0,
double stddev=1) : cRandom(rng), mean(mean), stddev(stddev) {}
206 cTruncNormal(
const cTruncNormal& other) : cRandom(other) {copy(other);}
207 virtual cTruncNormal *
dup()
const override {
return new cTruncNormal(*
this);}
209 virtual std::string
str()
const override;
214 void setMean(
double mean) {this->mean = mean;}
215 double getMean()
const {
return mean;}
216 void setStddev(
double stddev) {this->stddev = stddev;}
217 double getStddev()
const {
return stddev;}
222 virtual double draw()
const override;
235class SIM_API cGamma :
public cRandom
241 void copy(
const cGamma& other);
245 cGamma(
cRNG *rng,
double alpha,
double theta) : cRandom(rng), alpha(alpha), theta(theta) {}
246 cGamma(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double alpha=1,
double theta=1) : cRandom(rng), alpha(alpha), theta(theta) {}
247 cGamma(
const cGamma& other) : cRandom(other) {copy(other);}
248 virtual cGamma *
dup()
const override {
return new cGamma(*
this);}
250 virtual std::string
str()
const override;
255 void setAlpha(
double alpha) {this->alpha = alpha;}
256 double getAlpha()
const {
return alpha;}
257 void setTheta(
double theta) {this->theta = theta;}
258 double getTheta()
const {
return theta;}
263 virtual double draw()
const override;
276class SIM_API cBeta :
public cRandom
282 void copy(
const cBeta& other);
286 cBeta(
cRNG *rng,
double alpha1,
double alpha2) : cRandom(rng), alpha1(alpha1), alpha2(alpha2) {}
287 cBeta(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double alpha1=1,
double alpha2=1) : cRandom(rng), alpha1(alpha1), alpha2(alpha2) {}
288 cBeta(
const cBeta& other) : cRandom(other) {copy(other);}
289 virtual cBeta *
dup()
const override {
return new cBeta(*
this);}
291 virtual std::string
str()
const override;
296 void setAlpha1(
double alpha1) {this->alpha1 = alpha1;}
297 double getAlpha1()
const {
return alpha1;}
298 void setAlpha2(
double alpha2) {this->alpha2 = alpha2;}
299 double getAlpha2()
const {
return alpha2;}
304 virtual double draw()
const override;
317class SIM_API cErlang :
public cRandom
323 void copy(
const cErlang& other);
327 cErlang(
cRNG *rng,
unsigned int k,
double mean) : cRandom(rng), k(k), mean(mean) {}
328 cErlang(
const char *name=
nullptr,
cRNG *rng=
nullptr,
unsigned int k=1,
double mean=1) : cRandom(rng), k(k), mean(mean) {}
329 cErlang(
const cErlang& other) : cRandom(other) {copy(other);}
330 virtual cErlang *
dup()
const override {
return new cErlang(*
this);}
332 virtual std::string
str()
const override;
337 void setK(
unsigned int k) {this->k = k;}
338 unsigned int getK()
const {
return k;}
339 void setMean(
double mean) {this->mean = mean;}
340 double getMean()
const {
return mean;}
345 virtual double draw()
const override;
358class SIM_API cChiSquare :
public cRandom
363 void copy(
const cChiSquare& other);
367 cChiSquare(
cRNG *rng,
unsigned int k) : cRandom(rng), k(k) {}
368 cChiSquare(
const char *name=
nullptr,
cRNG *rng=
nullptr,
unsigned int k=1) : cRandom(rng), k(k) {}
369 cChiSquare(
const cChiSquare& other) : cRandom(other) {copy(other);}
370 virtual cChiSquare *
dup()
const override {
return new cChiSquare(*
this);}
372 virtual std::string
str()
const override;
377 void setK(
unsigned int k) {this->k = k;}
378 unsigned int getK()
const {
return k;}
383 virtual double draw()
const override;
396class SIM_API cStudentT :
public cRandom
401 void copy(
const cStudentT& other);
405 cStudentT(
cRNG *rng,
unsigned int i) : cRandom(rng), i(i) {}
406 cStudentT(
const char *name=
nullptr,
cRNG *rng=
nullptr,
unsigned int i=1) : cRandom(rng), i(i) {}
407 cStudentT(
const cStudentT& other) : cRandom(other) {copy(other);}
408 virtual cStudentT *
dup()
const override {
return new cStudentT(*
this);}
410 virtual std::string
str()
const override;
415 void setI(
unsigned int i) {this->i = i;}
416 unsigned int getI()
const {
return i;}
421 virtual double draw()
const override;
434class SIM_API cCauchy :
public cRandom
440 void copy(
const cCauchy& other);
444 cCauchy(
cRNG *rng,
double a,
double b) : cRandom(rng), a(a), b(b) {}
445 cCauchy(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double a=0,
double b=1) : cRandom(rng), a(a), b(b) {}
446 cCauchy(
const cCauchy& other) : cRandom(other) {copy(other);}
447 virtual cCauchy *
dup()
const override {
return new cCauchy(*
this);}
449 virtual std::string
str()
const override;
454 void setA(
double a) {this->a = a;}
455 double getA()
const {
return a;}
456 void setB(
double b) {this->b = b;}
457 double getB()
const {
return b;}
462 virtual double draw()
const override;
475class SIM_API cTriang :
public cRandom
482 void copy(
const cTriang& other);
486 cTriang(
cRNG *rng,
double a,
double b,
double c) : cRandom(rng), a(a), b(b), c(c) {}
487 cTriang(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double a=-1,
double b=0,
double c=1) : cRandom(rng), a(a), b(b), c(c) {}
488 cTriang(
const cTriang& other) : cRandom(other) {copy(other);}
489 virtual cTriang *
dup()
const override {
return new cTriang(*
this);}
491 virtual std::string
str()
const override;
496 void setA(
double a) {this->a = a;}
497 double getA()
const {
return a;}
498 void setB(
double b) {this->b = b;}
499 double getB()
const {
return b;}
500 void setC(
double c) {this->c = c;}
501 double getC()
const {
return c;}
506 virtual double draw()
const override;
519class SIM_API cWeibull :
public cRandom
525 void copy(
const cWeibull& other);
529 cWeibull(
cRNG *rng,
double a,
double b) : cRandom(rng), a(a), b(b) {}
530 cWeibull(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double a=1,
double b=1) : cRandom(rng), a(a), b(b) {}
531 cWeibull(
const cWeibull& other) : cRandom(other) {copy(other);}
532 virtual cWeibull *
dup()
const override {
return new cWeibull(*
this);}
534 virtual std::string
str()
const override;
539 void setA(
double a) {this->a = a;}
540 double getA()
const {
return a;}
541 void setB(
double b) {this->b = b;}
542 double getB()
const {
return b;}
547 virtual double draw()
const override;
560class SIM_API cParetoShifted :
public cRandom
567 void copy(
const cParetoShifted& other);
571 cParetoShifted(
cRNG *rng,
double a,
double b,
double c) : cRandom(rng), a(a), b(b), c(c) {}
572 cParetoShifted(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double a=1,
double b=1,
double c=0) : cRandom(rng), a(a), b(b), c(c) {}
573 cParetoShifted(
const cParetoShifted& other) : cRandom(other) {copy(other);}
574 virtual cParetoShifted *
dup()
const override {
return new cParetoShifted(*
this);}
576 virtual std::string
str()
const override;
581 void setA(
double a) {this->a = a;}
582 double getA()
const {
return a;}
583 void setB(
double b) {this->b = b;}
584 double getB()
const {
return b;}
585 void setC(
double c) {this->c = c;}
586 double getC()
const {
return c;}
591 virtual double draw()
const override;
606class SIM_API cIntUniform :
public cRandom
612 void copy(
const cIntUniform& other);
616 cIntUniform(
cRNG *rng,
int a,
int b) : cRandom(rng), a(a), b(b) {}
617 cIntUniform(
const char *name=
nullptr,
cRNG *rng=
nullptr,
int a=0,
int b=1) : cRandom(rng), a(a), b(b) {}
618 cIntUniform(
const cIntUniform& other) : cRandom(other) {copy(other);}
619 virtual cIntUniform *
dup()
const override {
return new cIntUniform(*
this);}
621 virtual std::string
str()
const override;
626 void setA(
int a) {this->a = a;}
627 int getA()
const {
return a;}
628 void setB(
int b) {this->b = b;}
629 int getB()
const {
return b;}
634 virtual double draw()
const override;
647class SIM_API cIntUniformExcl :
public cRandom
653 void copy(
const cIntUniformExcl& other);
657 cIntUniformExcl(
cRNG *rng,
int a,
int b) : cRandom(rng), a(a), b(b) {}
658 cIntUniformExcl(
const char *name=
nullptr,
cRNG *rng=
nullptr,
int a=0,
int b=1) : cRandom(rng), a(a), b(b) {}
659 cIntUniformExcl(
const cIntUniformExcl& other) : cRandom(other) {copy(other);}
660 virtual cIntUniformExcl *
dup()
const override {
return new cIntUniformExcl(*
this);}
662 virtual std::string
str()
const override;
667 void setA(
int a) {this->a = a;}
668 int getA()
const {
return a;}
669 void setB(
int b) {this->b = b;}
670 int getB()
const {
return b;}
675 virtual double draw()
const override;
688class SIM_API cBernoulli :
public cRandom
693 void copy(
const cBernoulli& other);
697 cBernoulli(
cRNG *rng,
double p) : cRandom(rng), p(p) {}
698 cBernoulli(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double p=0.5) : cRandom(rng), p(p) {}
699 cBernoulli(
const cBernoulli& other) : cRandom(other) {copy(other);}
700 virtual cBernoulli *
dup()
const override {
return new cBernoulli(*
this);}
702 virtual std::string
str()
const override;
707 void setP(
double p) {this->p = p;}
708 double getP()
const {
return p;}
713 virtual double draw()
const override;
726class SIM_API cBinomial :
public cRandom
732 void copy(
const cBinomial& other);
736 cBinomial(
cRNG *rng,
int n,
double p) : cRandom(rng), n(n), p(p) {}
737 cBinomial(
const char *name=
nullptr,
cRNG *rng=
nullptr,
int n=1,
double p=0.5) : cRandom(rng), n(n), p(p) {}
738 cBinomial(
const cBinomial& other) : cRandom(other) {copy(other);}
739 virtual cBinomial *
dup()
const override {
return new cBinomial(*
this);}
741 virtual std::string
str()
const override;
746 void setN(
int n) {this->n = n;}
747 int getN()
const {
return n;}
748 void setP(
double p) {this->p = p;}
749 double getP()
const {
return p;}
754 virtual double draw()
const override;
767class SIM_API cGeometric :
public cRandom
772 void copy(
const cGeometric& other);
776 cGeometric(
cRNG *rng,
double p) : cRandom(rng), p(p) {}
777 cGeometric(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double p=0.5) : cRandom(rng), p(p) {}
778 cGeometric(
const cGeometric& other) : cRandom(other) {copy(other);}
779 virtual cGeometric *
dup()
const override {
return new cGeometric(*
this);}
781 virtual std::string
str()
const override;
786 void setP(
double p) {this->p = p;}
787 double getP()
const {
return p;}
792 virtual double draw()
const override;
805class SIM_API cNegBinomial :
public cRandom
811 void copy(
const cNegBinomial& other);
815 cNegBinomial(
cRNG *rng,
int n,
double p) : cRandom(rng), n(n), p(p) {}
816 cNegBinomial(
const char *name=
nullptr,
cRNG *rng=
nullptr,
int n=0,
double p=0.5) : cRandom(rng), n(n), p(p) {}
817 cNegBinomial(
const cNegBinomial& other) : cRandom(other) {copy(other);}
818 virtual cNegBinomial *
dup()
const override {
return new cNegBinomial(*
this);}
820 virtual std::string
str()
const override;
825 void setN(
int n) {this->n = n;}
826 int getN()
const {
return n;}
827 void setP(
double p) {this->p = p;}
828 double getP()
const {
return p;}
833 virtual double draw()
const override;
846class SIM_API cPoisson :
public cRandom
851 void copy(
const cPoisson& other);
855 cPoisson(
cRNG *rng,
double lambda) : cRandom(rng), lambda(lambda) {}
856 cPoisson(
const char *name=
nullptr,
cRNG *rng=
nullptr,
double lambda=1) : cRandom(rng), lambda(lambda) {}
857 cPoisson(
const cPoisson& other) : cRandom(other) {copy(other);}
858 virtual cPoisson *
dup()
const override {
return new cPoisson(*
this);}
860 virtual std::string
str()
const override;
865 void setLambda(
double lambda) {this->lambda = lambda;}
866 double getLambda()
const {
return lambda;}
871 virtual double draw()
const override;
Generates random numbers that are the results of Bernoulli trials.
Definition crandom.h:689
virtual double draw() const override
virtual std::string str() const override
virtual cBernoulli * dup() const override
Definition crandom.h:700
Generates random numbers from the beta distribution.
Definition crandom.h:277
virtual cBeta * dup() const override
Definition crandom.h:289
virtual double draw() const override
virtual std::string str() const override
Generates random numbers from the binomial distribution.
Definition crandom.h:727
virtual double draw() const override
virtual std::string str() const override
virtual cBinomial * dup() const override
Definition crandom.h:739
Generates random numbers from the Cauchy distribution.
Definition crandom.h:435
virtual cCauchy * dup() const override
Definition crandom.h:447
virtual double draw() const override
virtual std::string str() const override
Generates random numbers from the chi-square distribution.
Definition crandom.h:359
virtual cChiSquare * dup() const override
Definition crandom.h:370
virtual double draw() const override
virtual std::string str() const override
Generates random numbers from the Erlang distribution.
Definition crandom.h:318
virtual cErlang * dup() const override
Definition crandom.h:330
virtual double draw() const override
virtual std::string str() const override
Generates random numbers from the exponential distribution.
Definition crandom.h:116
virtual double draw() const override
virtual cExponential * dup() const override
Definition crandom.h:127
virtual std::string str() const override
Generates random numbers from the gamma distribution.
Definition crandom.h:236
virtual double draw() const override
virtual std::string str() const override
virtual cGamma * dup() const override
Definition crandom.h:248
Generates random numbers from the geometric distribution.
Definition crandom.h:768
virtual double draw() const override
virtual cGeometric * dup() const override
Definition crandom.h:779
virtual std::string str() const override
Generates random numbers from the negative binomial distribution.
Definition crandom.h:806
virtual double draw() const override
virtual cNegBinomial * dup() const override
Definition crandom.h:818
virtual std::string str() const override
Generates random numbers from the normal distribution.
Definition crandom.h:154
virtual double draw() const override
virtual cNormal * dup() const override
Definition crandom.h:166
virtual std::string str() const override
Generates random numbers from the shifted Pareto distribution.
Definition crandom.h:561
virtual double draw() const override
virtual std::string str() const override
virtual cParetoShifted * dup() const override
Definition crandom.h:574
Generates random numbers from the Poisson distribution.
Definition crandom.h:847
virtual double draw() const override
virtual std::string str() const override
virtual cPoisson * dup() const override
Definition crandom.h:858
Abstract interface for random number generator classes.
Definition crng.h:49
cRNG * getRNG() const
Definition crandom.h:54
virtual double draw() const =0
virtual void setRNG(cRNG *rng)
Definition crandom.h:49
Generates random numbers from Student's T distribution.
Definition crandom.h:397
virtual double draw() const override
virtual std::string str() const override
virtual cStudentT * dup() const override
Definition crandom.h:408
Generates random numbers from the triangular distribution.
Definition crandom.h:476
virtual double draw() const override
virtual cTriang * dup() const override
Definition crandom.h:489
virtual std::string str() const override
Generates random numbers from the truncated normal distribution.
Definition crandom.h:195
virtual cTruncNormal * dup() const override
Definition crandom.h:207
virtual double draw() const override
virtual std::string str() const override
Generates random numbers from the Weibull distribution.
Definition crandom.h:520
virtual cWeibull * dup() const override
Definition crandom.h:532
virtual double draw() const override
virtual std::string str() const override