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

Exercises:
From the text (Budd's Classic Data Structures in Java), Chapter 3, pg 66:
Do numbers 3 and 4.

Programming Projects:
1.  Build upon your pseudorandom number generator from last week.  (Again, this problem is adapted from Data Structures & Other Objects Using Java, Mark Main.)

First, if you only had one constructor that took four arguments, add a second (default) constructor that takes zero arguments but initializes the seed, multiplier, increment and modulus to some reasonable values.  (The values given in Assignment 2 would be good candidates.)

Next, add a method to your class that causes the generation of the next pseudorandom number but does not return it directly.  This new method should return a double value between 0.0 (inclusive) and 1.0 (exclusive).  You can accomplish this by dividing the generated number by your modulus.  (Note, since the number generated by your method from last week is the remainder of a division by the modulus, it will never be greater than or equal to the modulus.  Therefore, when dividing by the modulus, the quotient will always be strictly less than 1.0.)  If one repeatedly calls this new method, it should generate a pseudorandom sequence in the range [0.0 .. 1.0).

Once your new method is generating such numbers, run experiments that evaluate the distribution of resulting numbers.  You'll probably run these experiments from a main method, perhaps in another class.  Break the range [0..1) into ten smaller ranges: [0.. 0.1), [0.1 .. 0.2), ... [0.9 .. 1.0).  For a large sequence of numbers, say a million, accumulate the number of pseudorandom numbers that were generated in each of these smaller ranges.  Finally, print out a table such as this:

Range   Number of Occurances
[0.0..0.1)   99889
[1.0..0.2)   100309
...
[0.9..1.0)   99904

Run your experiment several times with different values for the multiplier, increment, and modulus.  A set of good choices for these will yield approximately 10% of the total in each range.  A generator with this equal-interval behavior is called uniformly distributed.  Try to find a set of values that produce a better distribution than the values recommended in Assignment 2.

Submission Instructions:
On your machine where you are doing your homework, create a folder called <your email name> followed by "A3".  For example, someone with email address "cjones" would create a folder called "cjonesA3".  Inside that folder, place plain text file(s) containing your answers to any exercises.  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>A3" will be createdIf 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.