CS1030 -- Lab 4: Pseudorandom Number Generator Class

Spring 2005
Objectives Addressed
Procedures

You should write implement a pseudorandom number generator class called Random, with at least two member functions: cstdlibRandom() and powerResidueRandom(). Both functions should return a pseudorandom number between 0.0 and 1.0. The first function should make use of the rand function from the cstdlib library. The second function should generate pseudorandom numbers using the power residue technique described below.

You should also modify your Complex class (implemented as part of homework 5) so that the default constructor generates a complex number with pseudorandom real and imaginary components between -9,999.99999 and 9,999.99999, and so that it is possible to use the insertion operator (operator<<) to insert complex numbers into an output stream.

In addition, you should write a program which generates five random numbers between 0.0 and 1.0 using the two functions from the Random class (total of 10 numbers) and twenty-five complex numbers using the revised default constructor. These values should be appropriately identified and written to a file called random.dat.

Power Residue Pseudorandom Number Generator

The power residue method is an alternative way of generating pseudorandom numbers. In order to generate pseudorandom integer numbers between 0 and 10n, we begin with an n-digit integer called the seed. In order to get a seemingly random sequence, the seed should be at least four digits long and not be divisible by 2 or 5. You may wish to select this number using the time() function in a way that is similar to setting the seed for the rand() function. The seed is then multiplied by (10n/2 - 3). The lowest n digits of the result is the pseudorandom number generated and is used as the seed for the next pseudorandom number in the sequence.

For example, if we begin with a seed of 234567, we then multiply by (103 - 3) = 997 to get 233863299. The residue of this number is 863299, the second pseudorandom number generated. This is then multiplied by 997 to get 860709103. Therefore, 709103 is the next number generated.

I would suggest that you use long unsigned int for the data type representing the seed for the power residue pseudorandom number generator.

Lab submission (due at the end of lab)

Before you leave lab, you should submit your source code files as one zip file and the data file as the support file.

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.

Last Updated: Thursday, 01-Jan-2015 13:31:59 CST