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

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

Do numbers 1 and 3.

Programming Projects:
1.  (from the text, pg 47) Do #1.

2.  Also do the following (adapted from Data Structures & Other Objects Using Java, Mark Main):  Design and implement a pseudorandom number generator class.  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>A1" will be created.  If you choose to use zip instead of tar, change the extension of the resulting zip file from "<something>.zip" to "<something>.foo".  This way, our webmail will allow you to attach the file.  If I get an attachment with extension .foo, I will change it back to .zip and all should be well.