#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 |
long | pHigh |
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.
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.
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" |
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.
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 |
long DiscreteUniform::low | ( | ) | const [inline] |
long DiscreteUniform::high | ( | ) | const [inline] |
void DiscreteUniform::low | ( | long | lo | ) | [inline] |
void DiscreteUniform::high | ( | long | hi | ) | [inline] |
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 |
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 >.
double DiscreteUniform::p | ( | const long & | x | ) | const [virtual] |
Returns the probability for the occurrence of random number "x".
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.
Implements RandomVar< long >.
long DiscreteUniform::pLow [protected] |
long DiscreteUniform::pHigh [protected] |