Next: Hush classes Up: Program structure Previous: The simulation class

## The generator class

The class generator represents the random number generator. The generator is used to get the randomized activation times of the various events. It gets three positive seeds and creates a random number stream, according to the method described in appendix A.

Each time a member of the generator is invoked to get a random number, the next number from the stream is calculated and is transformed, according to the probability distribution belonging to that member. Refer to appendix B for the definitions. This number is returned and can be used in the simulation. If, for example, a normal distribution with 10 as mean and 1 as standard deviation is specified to transform the random number stream, the generated numbers have 10 as mean and show little variation because of the low standard deviation.

The class generator has the following interface :

```   interface generator
{
public :
generator(unsigned int s1,unsigned int s2 = 0,unsigned int s3 = 0);

void antithetic(); // use 1-random()

void reset();      // reset random number stream

int probability(double p = 0.5); // OK with prob. p

double uniform(double a,double b);
double exponential(double a);
double hyperexponential(double p,double a,double b);
double laplace(double a);
double normal(double a,double b);
double chisquare(unsigned int n);
double student(unsigned int n);
double lognormal(double a,double b);
double erlang(unsigned int n,double a);
double gamma(double a,double b);
double beta(double a,double b);
double fdistribution(unsigned int n,unsigned int m);
double poisson(double a);
double geometric(double p);
double hypergeometric(unsigned int m,unsigned int n,double p);
double weibull(double a,double b);
double binomial(double p,unsigned int n);
double negativebinomial(double p,unsigned int n);
double triangular(double a);

protected :
double random();    // produces a random number between 0 and 1
};
```

A generator, with given seeds, produces the same random number stream every time, it is created with those seeds. If the defaults are chosen the last two seeds are equal to the first one. One should fluctuate seeds to get reliable random numbers.

If the method antithetic is invoked, the inverse of the current stream is used, i.e. instead of the generated random number, say x, 1-x is used. This method can be used when the variance of the samples made is too high.

The function reset resets the random number stream, as if no random number was generated from this stream. The member probability returns OK with probability p and FALSE with probability 1-p. The distribution functions all return a random number from the stream, following the belonging probability distribution. The method random produces a new variate (between 0 and 1) from the random number stream. It is made protected so a derived generator can use this stream and add new distributions to the existing ones.

Next: Hush classes Up: Program structure Previous: The simulation class

A Eliens
Tue Oct 31 09:27:21 MET 1995