This class simulates a "uniform distribution" with integer numbers. More...
#include <DiscreteUniform.h>
Public Member Functions | |
| DiscreteUniform (long lo=0, long hi=1) | |
| Creates a new instance of the discrete uniform random number generator and initializes the lower and upper bound. | |
| DiscreteUniform (long lo, long hi, RNG &rng) | |
| Creates a new discrete uniform random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the interval bounds for the random numbers. | |
| long | low () const |
| Returns the lower (included) bound pLow for the random numbers interval. | |
| long | high () const |
| Returns the upper (excluded) bound pHigh for the random numbers interval. | |
| void | low (long lo) |
| Sets the lower (included) bound pLow for the random numbers interval to the new value "lo". | |
| void | high (long hi) |
| Sets the upper (excluded) bound pHigh for the random numbers interval to the new value "hi". | |
| long | operator() (long lo, long hi) |
| Returns a uniformally distributed discrete random number from the interval ["lo", "hi"]. | |
| long | operator() () |
| Returns a uniformally distributed discrete random number from the interval [pLow, pHigh]. | |
| double | p (const long &) const |
| Returns the probability for the occurrence of random number "x". | |
Protected Attributes | |
| long | pLow |
The lower bound of the random number interval pLow, pHigh . | |
| long | pHigh |
The upper bound of the random number interval pLow, pHigh . | |
This class simulates a "uniform distribution" with integer numbers.
This class is derived from class RandomVar and the uniformally distributed pseudo random number values of the interval (0,1) are transformed to type "long" and are from an interval
pLow, pHigh
.
This class is similar to class Uniform, but here the distribution is not continuous but discrete, so you will receive integer random numbers instead of double random numbers.
Definition at line 75 of file DiscreteUniform.h.
| DiscreteUniform::DiscreteUniform | ( | long | lo = 0, |
|
| long | hi = 1 | |||
| ) |
Creates a new instance of the discrete uniform random number generator and initializes the lower and upper bound.
The lower bound pLow and the upper bound pHigh for the interval, from which the random numbers are taken, are initialized.
For this instance, the default pseudo random number generator as member of class RandomVar is used.
| lo | initial value for the lower bound pLow, by default set to "0" | |
| hi | initial value for the upper bound pHigh, by default set to "1" |
Definition at line 73 of file DiscreteUniform.cpp.
| DiscreteUniform::DiscreteUniform | ( | long | lo, | |
| long | hi, | |||
| RNG & | r | |||
| ) |
Creates a new discrete uniform random generator instance by using the pseudo random number generator "r" for the determination of random values and initializes the interval bounds for the random numbers.
Each instance of a discrete uniform random number generator is based on a generator, that is defined in class RNG and returns uniformally pseudo random numbers of the interval (0,1). By default, this is a global generator named RNG::globalRng and included as member in class RandomVar.
Here another pseudo random number generator r is used instead.
Additionally to defining the used pseudo random number generator, the lower and the upper bound for the random numbers interval are initialized.
| lo | initial value for the lower bound pLow | |
| hi | initial value for the upper bound pHigh | |
| r | the pseudo random number generator that is used |
Definition at line 110 of file DiscreteUniform.cpp.
| void DiscreteUniform::high | ( | long | hi | ) | [inline] |
Sets the upper (excluded) bound pHigh for the random numbers interval to the new value "hi".
| hi | the new value for the upper bound pHigh |
Definition at line 180 of file DiscreteUniform.h.
References pHigh.
| long DiscreteUniform::high | ( | ) | const [inline] |
Returns the upper (excluded) bound pHigh for the random numbers interval.
Definition at line 132 of file DiscreteUniform.h.
References pHigh.
| void DiscreteUniform::low | ( | long | lo | ) | [inline] |
Sets the lower (included) bound pLow for the random numbers interval to the new value "lo".
| lo | the new value for the lower bound pLow |
Definition at line 156 of file DiscreteUniform.h.
References pLow.
| long DiscreteUniform::low | ( | ) | const [inline] |
Returns the lower (included) bound pLow for the random numbers interval.
Definition at line 109 of file DiscreteUniform.h.
References pLow.
| long DiscreteUniform::operator() | ( | ) | [virtual] |
Returns a uniformally distributed discrete random number from the interval [pLow, pHigh].
Returns a uniformally distributed discrete random number from the interval [pLow, pHigh[.
A discrete random number
with pLow
pHigh is returned.

Implements RandomVar< long >.
Definition at line 135 of file DiscreteUniform.cpp.
| long DiscreteUniform::operator() | ( | long | lo, | |
| long | hi | |||
| ) | [inline] |
Returns a uniformally distributed discrete random number from the interval ["lo", "hi"].
This method performs the inverse transformation of the original uniformally distributed random numbers of the interval (0,1) created by the used pseudo random number generator to the type of the discrete uniform distribution, i.e. a discrete random number
with
is returned.
| lo | the minimum random number that can be returned | |
| hi | the upper bound for random numbers that can be returned |

Definition at line 212 of file DiscreteUniform.h.
References RandomVar< long >::rng.
| double DiscreteUniform::p | ( | const long & | x | ) | const [virtual] |
Returns the probability for the occurrence of random number "x".
The probability
is returned, where the interval length is given by pHigh - pLow + 1. If x is not a member of the interval, "0" is returned instead.
or "0" if x is not an interval memberImplements RandomVar< long >.
Definition at line 164 of file DiscreteUniform.cpp.
long DiscreteUniform::pHigh [protected] |
The upper bound of the random number interval
pLow, pHigh
.
Definition at line 234 of file DiscreteUniform.h.
Referenced by high(), operator()(), and p().
long DiscreteUniform::pLow [protected] |
The lower bound of the random number interval
pLow, pHigh
.
Definition at line 230 of file DiscreteUniform.h.
Referenced by low(), operator()(), and p().