Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
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 defines the RandomVariable interface. The RandomVariable interface provides the single method nextDouble. Given an instance, say rv, of a class that implements the RandomVariable interface, repeated calls of the form

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

   program33569
Program: RandomVariable interface.




next up previous contents index

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