# Exercises 3: How Random is Pseudorandom?

For this assignment, you will extend your work from Exercise 2 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,
• and 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 2 we partially addressed the distribution question; in this assignment we consider the sequence.

When considering the sequence of a random number generator, we look at the frequency of ranges as before, but in the context of pairs of 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

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).
• create 2-d array of ints to store counts of pairs of random numbers. A pair is two consecutive numbers generated by your random number generator.
• generate numSamples of numbers, populating the 2-d array you created. Note: there will be one less than numSamples pairs.
• Now print the 2-d array you populated in a row/column format.
3. public static void main(String[] args). Write a main method that creates an instance of your PRNG 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 Exercise 2. 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 “Ex3”. For example, someone with email address “cjones” would create a folder called “cjonesEx3”. 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>Ex3” will be created. Submit the packaged file for this exercise on Eureka.