# Exercises 5.1: How Random is Pseudorandom?

For this assignment, you will extend your work from Exercise 4.x in order to better assess the quality of the sequnce that is generated by your random number generator.

### Objectives for this assignment

The goals for this assignment is to provide you with: more practice using Java and working with arrays, improved understanding of constructors and inheritance, broadened understanding of pseudo random number generators.

### Evaluating pseudorandom number generators

There are many applications of pseudorandom number generators. For some of those applications, the particular properties or characteristics of the distribution and sequence are of critical importance. In exercises 4.x we partially addressed the distribution question; in this assignment we consider the sequence.

One measure of the quality of the sequence that is give by a particular mechanism is to look at frequencies of pair-wise numbers. That is, if we were generating ten distinct numbers, we would hope that for every one of the ten numbers, each of the ten is equally likely to follow. This would reveal a problem with a generator that yields the sequence: 0,1,2,3,4,5,6,7,8,9,0,1,2,3,... and so on. Note, this generator has a perfect distribution but the sequence is terrible. By keeping track of the number of times each number follows 0 (and similarly each of the other numbers), we would can detect this problem.

### Problem requirements: Part I

Write a new class, TestGenerator, which should test a single random number generator instance at a time.

1. public static void testDistribution(RandI rg, int numBins, int numSamples). This method should function similarly to and may be thought of as a combination of sample and report methods from RandDriver. The method should use the given instance of a random generator in its given state and generate numSamples samples, incrementing the counts of an array that is created for this purpose having numBins bins. Note: as a static method, it may be called without creating an instance of the TestGenerator class. The array needs to be dynamically created for the given number of bins and the placement of a random number into one of the bins needs to be determined accordingly.
2. public static void testSequence(RandI rg, int numBins, int numSamples). This method should create a two-dimensional array that numBins rows and columns. As before, your method should generate numSamples random numbers, but now the cell in your array that is indexed by i and j should contain the number of times that a random number landing in the i bin is followed by a random number landing it the j bin. After generating the numbers and recording the pairwise frequencies, you should display the array as rows and columns so that we can visually see the uniformity of the sequence (or lack thereof).
3. public static void main(String[] args). Write a main method that creates an instance of your MyPRNG random number generator and tests its properties using the two static methods you have written. Run this several times with different values for the multiplier, increment, modulus and seed. A set of good choices for these values will yield approximately equal fractions of the total samples in each range. A generator with this equal-interval behavior is called uniformly distributed. Similarly, the sequence should be evenly distributed over the two-dimensional array. Try to find a set of values that produce a better distribution than the values recommended in Exercises 4.x. If you find such a set of numbers, describe the comparison to the original values and include them in your documentation and as default values.

### Submission instructions:

Make sure that you create a folder named with your Westmont email name followed by “Ex5.1”. For example, someone with email address “cjones” would create a folder called “cjonesEx5.1”. Make sure that inside that folder you have: java source files as well as html documentation files resulting from javadoc. Finally, either tar or zip the folder so that when we extract it, the folder “<emailname>Ex5.1” will be created. Submit the packaged file for this exercise on Eureka.