CS30 -- Introduction to Computer Science II
Fall, 2005
Assignment 2
(updated 9/6/2005)

From the text (Budd's Classic Data Structures in Java), Chapter , pg 47:

Exercises:
Do number 2.

Programming Projects:

1.  Do the following (adapted from Data Structures & Other Objects Using Java, Mark Main):  Design and implement a pseudorandom number generator class.  Your class should implement the Enumeration interface.  Computers cannot generate "truly" random numbers.  Instead, they compute a sequence of "pseudorandom" numbers that appear random.  The basic approach is the linear congruence method.  The sequence generated is dependent upon a seed, a multiplier, the increment, and the modulus.  The formula for generating the next pseudorandom number in the sequence is:

(multiplier * seed + increment) % modulus

The seed is initially set by one of several schemes; for our purposes, it is an input to the constructor.  After the first pseudorandom number has been generated, the seed is always set to the most recently generated number.  For example: with multiplier, increment and modulus values of 40, 3641 and 729 respectively, and an initial seed of 1, our first pseudorandom number would be:

(40 * 1 + 3641) % 729 = 36

and the seed is set to 36.  The next would be

(40 * 36 + 3641) % 729 = 707

with the seed now equal to 707.  And so on.

For this programming assignment, design and implement a class that can generate a pseudorandom sequence in the manner just described.  The multiplier, increment and modulus and initial seed should be parameters to the constructor.  You should provide a method that can set the seed to a given value and of course you should provide a method that generates and returns the next pseudorandom number given the current value of the seed.

Submission Instructions:
On your machine where you are doing your homework, create a folder called <your email name> followed by "A2".  For example, someone with email address "cjones" would create a folder called "cjonesA2".  Inside that folder, place plain text file(s) containing your answers to numbers 1 and 3.  Also, place whatever Java files are necessary for your Programming Projects in the same folder.  Finally, either tar or zip the folder so that when I extract it, the folder "<emailname>A2" will be created.  Finally, submit the packaged file for assignment 2 on Eureka.