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

Random Variables

In this section we introduce the notion of an abstract random variable . In this context, a random variable is an object that behaves like a random number generator in that it produces a pseudorandom number sequence. The distribution of the values produced depends on the class of random variable used.

Program gif declares several random variable classes. The abstract RandomVariable class defines the shared interface. A single, pure virtual member function is declared--Sample. Given an instance, say rv, of a concrete class derived from RandomVariable, repeated calls of the form

rv.Sample ();
are expected to return successive elements of a pseudorandom sequence.

   program34040
Program: RandomVariable, SimpleRV, UniformRV and ExponentialRV Class Definitions

Program gif also declares three concrete random variable classes:

SimpleRV
This class generates random numbers uniformly distributed in the interval (0,1). (It is merely a wrapper for the RandomNumberGenerator defined in the preceding section).
UniformRV
This class generates random numbers which are uniformly distributed in an arbitrary interval (u,v), where u<v. The parameters u and v are specified in the constructor.
ExponentialRV
This class generates exponentially distributed random numbers with a mean value of tex2html_wrap_inline69431. The mean value tex2html_wrap_inline69431 is specified in the constructor.




next up previous contents index

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