# Probability Distribution Namespace Homepage

Welcome to the homepage for the Probability Distribution Namespace. Current version August 2001. This is a C++ namespace providing some rudimentary, but extensible facilities relating to discrete probability density functions. It is coded in ANSI C++ and is made available to you subject to the terms of the GNU General Public Licence.

Please email opensource@ascent.zetnet.co.uk with any queries or suggestions regarding open source ANSI C++.

The following abstract base class gives the minimum facilities which any derived class must provide:

``````
//distribution class to serve as base class
class Distribution
{
public:
//operations
virtual long draw() const =0;           //draw one number from distribution
virtual double mean() const =0;
virtual double variance() const =0;
virtual void test(int n) const =0;       //test distribution by performing n draws
virtual ~Distribution() {};
};
``````

The three derived classes listed below provide discrete uniform, binomial and Poisson distributions. The non-uniform distributions' `draw()` functions are implemented by first drawing a uniformly distributed number. This number is then used to decide the return value based on which rescaled interval it falls within. In this way, it is fairly straightforward to derive classes for new discrete distributions. Adding functions to return the actual probability density function and cumulative density function might be useful.

• `class Uniform : public Distribution {...};`
• `class Binomial : public Distribution {...};`
• `class Poisson : public Distribution {...};`

The constructors can take a seed, for seeding the random number generator. If no seed is specified, a seed will be chosen based on currect system time. In other words, this provides you with the possibility of repeatable runs. Construction with a specified seed will always generate the same sequence of random numbers.

Each class has a default distribution, which allows you to instantiate a distribution without specifying any parameters (parameters will be copied from the default). You can change the properties of the default distribution using the `set_default()` function.

Each class overrides the `draw()` function, which will return one random result from the object on which it is invoked. Over a number of draws the results will reflect the distribution.

The `test(int n)` member facilitates testing of a distribution by performing and binning `n` (default n = 10000) draws on the distribution. The results of the test are then output to the console.

N.B. - conformance testing is not yet complete

d