Homework 2
Introduction
You will implement a general-purpose linear congruential generator (LCG) function. You will compare the LCG using two specific initial settings against the default U[0,1) random number generator supplied by the Random library of your programming language (which may or may not have used a LCG). For each setting, you will generate a stream of pseudo-random numbers in the range [0, 1) (i.e. between 0 and 1, including 0, excluding 1). You should test each stream for uniformity and independence by applying four statistical tests:
- Kolmogorov-Smirnov Test
- Chi-Square Test
- Runs Test
- Autocorrelations Test
Finally, you will analyze and present your findings in a well-written, well-organized report.
Program Specifications
You may develop your program Java, C, C++, C#, Python, or a language of your choice (pending approval of the TA). Your program should provide some reasonable input prompts for the user (i.e., the TA), and its output should be stored and/or displayed in some reasonable way. For example, the program should ask the user to select a function setting to generate random numbers, how many numbers to generate, etc.; it should ask the user to select a statistical test to run; it should save the stream of generated numbers to a file rather than let them scroll across the screen.
You should prepare a README file (separate from the analysis report) for the grader. It should explain how to run your program and provide any other relevant information that might help the grader evaluate your program.
Generation Function Settings
Choose the same seed (X0) for all three cases (for example, X0=123456789). You should specify the seed value you used in the report.
- The standard random number generator for your programming language.
- Make sure you are using a function that returns a number between 0 and 1 according to the uniform distribution. (In Java's random library, that would be the NextDouble function.)
- You should look up your compiler's references to find out how the random function is implemented. You should include this information in the report portion of the assignment.
- Your implementation of the LCG using the following initial setting:
- a = 101427, c = 321, m = 216
- Obtain each number in U[0,1) by dividing Xi by m
- Your implementation of the LCG using the RANDU initial setting
- a = 65539, c = 0, m = 231
- Obtain each number in U[0,1) by dividing Xi by m
Statistical Tests
You will check for uniformity and independence of the numbers generated by the three methods above by applying the following statistical tests. You should check for significance at the 80%, 90%, and 95% level. Note that some tests are one-sided while others are two-sided.
- Chi-Square Frequency Test for uniformity
- Collect 10,000 numbers per generation method.
- You should sub-divide [0,1) into 10 equal subdivisions.
- Kolmogorov-Smirnov Test for uniformity
- Since the K-S Test works better with a smaller set of numbers, you may use the first 100 generated numbers out of the 10,000 you generated for the Chi-Square Frequency Test.
- Runs Test for independence
- Use all 10,000 numbers per method for this test.
- Autocorrelations test for independence
- Use all 10,000 numbers per method.
- This is really a set of tests rather than one test, since we should consider different parameterizations. For this assignment, you should experiment with at least the following gap sizes (parameter l in our notes): 2, 3, 5, 50. But we won't consider different starting points (parameter i in our notes); simply choose one and specify what you used in the report.
- If you find the lecture notes sparse on details, these sites should help guide you on implementing this test:
Write-Up / Analysis
Once you have done all of your tests, you must look over and analyze your results and present them in a well-written, well-formatted report. Your report should include a discussion of the following:
- What is the random library function that your compiler supplied for you?
- Summarize the outcomes of the statistical tests for each RNG method in a formatted, easy to understand table. What test(s) did the method "pass"? Be specific about the condition (i.e., at what level of significance).
- For each method, prior to generating the numbers and running the statistical tests, do you expect it to work well or poorly? Explain.
- Looking over some of the generated numbers for each method (but before running the statistical tests), do you think they look sufficiently random? Did the outcome of the statistical test surprise you?
- Discuss whether you think the set of experiments you did for this assignment is sufficient. If so, argue why that is the case. If not, explain what additional test(s) or modification(s) to the methodology you'd perform.
Submission and Grading:
The assignment is due Wednesday, February 17 by 11:59 pm.
Zip your source code files, your write-up, and your README into one zip file and upload it to CourseWeb, in the Homework 2 location.
For more advice on submitting your assignment, see the Assignments section of the Tips for Success page.