|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
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
defines the RandomVariable class.
The abstract RandomVariable class
extends the abstract Object class
introduced in Program
.
The RandomVariable class defines the property next.
Given an instance, say rv,
of a class derived from the RandomVariable class,
repeated accesses to the next property
are expected to return successive elements of a pseudorandom sequence.

Program: Abstract RandomVariable class.