Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Implementation

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

   program34075
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 tex2html_wrap_inline69439 uniformly distributed on the interval (0,1), the linear transformation

displaymath69435

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

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

displaymath69436

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

eqnarray34110

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

  eqnarray34118

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


next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.