file name: distrib.hpp, distrib.cpp
author: Gerald Hummel
classification: simulation
contents: struct SRandomData, class distributions, class CUniform,
class C_exponential, class C_normal, class C_gamma, class C_weibull, class
C_generic, class CRandom
use: provides all random classes used in the simulation
Note: The classes were developed by Gerald Hummel in the course of an Informatik-Praktikum. A documentation manual is available (paper only).
Note: There have been some additions and changes to the original code to adapt it to the needs of SimUTC. The documentation below only covers the added structure SRandomData and the interface part of modified class CRandom which is used by SimUTC. An important modification has been done to make random streams start from a different offset at every start of the program. Global variable g_streamOffset is used to achieve this. It is added to the deterministic offset and if it is initialized differently at every program start, then the random generators will always start from a different offset, making the simulation behaviour more indeterministic.
Note: In DOS, several constants and an external variable are
not available and have to be defined in the implementation file. The variable
stores the sign for the Gamma function, and since in Linux it
is declared somewhere else, the sign might also be influenced by some other
function, so you should probably not use this distribution function if
DOS_SIM
is defined. The constants hold the value of pi and the limits
of a double value. The latter affect the computation of the limits
of a distribution function and are hopefully set to reasonable values.
You should not notice any adverse effects.
global items defined:
int SizeOfSeries:
The size of the array used as input for the random generator.
struct
SRandomData: Contains all necessary data for choosing a random variable
in a given interval according to a given distribution function.
global items used by SRandomData:
member variables of SRandomData:
double constant:
the constant value that is added to the random variable before it is returned
default value: 0
EDistribution
dist: the distribution function
default value: Uniform
double freeparam:
a second parameter whose meaning depends on the selected distribution
default value: 0
double high:
the upper bound on the interval of the random number
default value: 0
double low:
the lower bound on the interval of the random number
default value: 0
double mean:
the mean value; it should be within [low, high]
default value: 0
member functions of class SRandomData:
SRandomData():
default ctor; sets all members to their default values
EBool DataValid():
checks if low>=0, low+constant>=0, low<=mean<=high
and returns True if all three conditions are fulfilled, otherwise False
global items used by CRandom:
member functions of class CRandom:
CRandom
(int streampos = 0): Creates the random streams, initializes them
with streampos.
EBool CastDice
(double prob): Returns True with probability prob.
If prob is not in the interval [0,1], an assert fails.
virtual
void GetSeeds (EDistribution dist, long& mgSeed, long& lcgSeed,
long& distance) const: Returns the seeds of the generators. If
the distribution is not supported, an assert fails.
double RandomVar
(EDistribution dist): Returns a random number. The parameters of the
distribution must already have been set with function Set().
double RandomVar
(SRandomData& data):
double
RandomVar (EDistribution dist, double c, double low, double high, double
mean, double freeparam=0): Both functions return a random number out
of the given interval according to the given distribution. If the distribution
is not supported, an assert fails.
double RandomVar
(double low, double high): Returns a uniform random number out of
the given interval.
void Set(EDistribution
dist, double c, double low, double high, double mean, double free_par=0):
Sets the parameters of the given distribution.
Set_generic(double
c, double low, double high, double *inv_funct, unsigned long tabsize):
Sets the parameters and a table containing the inversion function for the
generic distribution.
virtual
void SetSeeds (EDistribution dist, long mgSeed, long lcgSeed, long distance):
Takes over the seeds for the generator. If the distribution is not supported,
or if either mgSeed or lcgSeed are not positive, an assert
fails.