-- Introduction to Computer Science II
From the text (Budd's Classic Data Structures in Java),
Chapter , pg :
Exercises: Do numbers 1 and 3.
Programming Projects: 1. (from the text, pg 47)
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.
On your machine where you are doing your homework, create a folder
called <your email name> followed by "A2". For example,
with email address "cjones" would create a folder called
Inside that folder, place plain text file(s) containing your answers to
numbers 1 and 3. Also, place whatever Java files are necessary
your Programming Projects in the same folder. Finally, either tar
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
webmail will allow you to attach the file. If I get an attachment
extension .foo, I will change it back to .zip and all should be well.