8.5 Random Distributions

Random distributions in PDP++ are handled by an instance of the class Random. This class has a number of functions which return a random number from the distribution named by the function. Alternately the distribution can be specified in the object itself in which case the Gen() function returns a value from the specified distribution. Many of the distributions require parameters which are again either passed to the specific functions or set on the Random object itself.

Random class Variables:

Type type
Indicates the type of random variable to generate when the Gen() function is called. It can have one of the following values:
UNIFORM
A uniform distribution with var = half-range
BINOMIAL
A binomial distribution with var = p, par = n
POISSON
A Poisson distribution with var = lambda
GAMMA
A gamma distribution with var and par = stages
GAUSSIAN
A normal gaussian distribution with var
NONE
Returns the mean value
float mean
The mean of a random distribution
float var
The "variance" or rough equivalent (half-range)
float par
An extra parameter used for some distributions

Random Class Functions

float ZeroOne()
Returns a uniform random number between zero and one
float Range(float rng)
Returns a uniform random number with a given range centered at 0
float Uniform(float half_rng)
Returns a uniform random number with given half-range centered at 0
float Binom(int n, float p)
Returns a random number from a binomial distribution with n trials each of probability p
float Poisson(float l)
Returns a random number from a Poisson distribution with parameter l
float Gamma(float var, int j)
Returns a random number from a Gamma distribution with variance var and par number of exponential stages
float Gauss(float var)
Returns a gaussian (normal) random number with a variance var
float Gen()
Returns a random number using the distributions type type and the mean, var, and par variables on the Random object itself.