FHTW Berlin Medieninformatik

FHTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2008/09


Exercise 10: An Element of Randomness

Finger exercises
  1. What would be good values of A and M for pseudo random number generators using the linear congruential method?
 

Lab exercises

  1. Implement your own pseudo random number generator using the linear congruential method.
  2. Now test your generator against the java.util.Random generator! Set up a window with two square frames of the same size. Use one frame for your generator, one for the java.util.Random generator. Generate 10.000.000 numbers between 0 and the size of the frame. Use subsequent numbers for the x and the y and plot the results in the frames, setting the dot (x,y) to be a colored dot.
  3. Implement some statistical tests that you run on the numbers generated. How well does your algorithm do, how well does the Java algorithm do?
    1. There should be an equal number of ones and zeros in the sequence
    2. There should be an equal number of even and odd numbers
    3. The sum of two subsequent numbers should be equally likely to be even or odd
    4. Each number is equally likely
    5. The average of all the numbers generated is N/2 if N is the number of bits in your window.
  4. (For the bored) What is a chi-squared test? Can you develop one to use on the random number generators used?
  5. (For the bored) Try out different values for A and M - which one has the best = longest period?

 


Copyright 2008 Prof. Dr. Debora Weber-Wulff
All rights reserved.
Questions or comments: <weberwu@fhtw-berlin.de>
Copyright and Warranty