Data Structures and Algorithms with Object-Oriented Design Patterns in C++

### Implementation

Program  gives the implementations for the three concrete random variable classes declared in Program .

Program: SimpleRV, UniformRV and ExponentialRV Member Function Definitions

The implementation of the SimpleRV class is trivial because the RandomNumberGenerator class generates the desired distribution of random numbers. Consequently, the SimpleRV::Sample function simply calls RandomNumberGenerator::Next.

The UniformRV class is also quite simple. Given that the RandomNumberGenerator class generates a sequence random numbers uniformly distributed on the interval (0,1), the linear transformation

suffices to produce a sequence of random numbers uniformly distributed on the interval (u,v).

The ExponentialRV class generates a sequence of random numbers, , exponentially distributed  on the interval and having a mean value . The numbers are said to be exponentially distributed because the probability that falls between 0 and z is given by

where . The function p(x) is called the probability density function . Thus,

Notice that is a value between zero and one. Therefore, given a random variable, , uniformly distributed between zero and one, we can obtain an exponentially distributed variable as follows:

Note, if is uniformly distributed on (O,1), then so too is . The implementation of the ExponentialRV::Sample function follows directly from Equation .