Embed
Email

Word

Document Sample

Shared by: ajizai
Categories
Tags
Stats
views:
0
posted:
12/20/2011
language:
pages:
4
ALG0183 Algorithms and Data Structures







Laboratory 3



A random number generator can be tested by visually examining scatter diagrams of {(xi, xi+1)} or {xi,

xi+2)}, etc. If the sequence of numbers from the random number generator is random, you would expect

to see points randomly scattered. Any structure indicates non-randomness and possibly degeneracy (not

full period) in the random number generator.



Part A

Execute the applet on the ALG0183 website by Peter Alfeld and answer questions 1-7. The formula for a

linear congruential generator is normally written:



xn = (a * xn-1) mod M

xn = (P1 * xn-1 + P2) mod N



In the diagram below, N is M, P1 is a, and P2 is a constant term added to the product before the mod

operation. Normally P2 is zero. The “” buttons single step through values and the “>”

buttons step through by larger amounts. When interacting with the control window it is important to

press the enter key if you make a direct change to a number. You can vary the dot size and the number

of dots to be displayed. You will not need to look at more than one cycle at once in this exercise. The k in

(xi, xi+k) is currently set to 1 for Cycle 1 in the control window below. The top right button in the control

window (currently reading default) can be used to examine preset values for well-known generators.









1

ALG0183 Algorithms and Data Structures







1. a = 3 M = 17 (no constant term) seed = 1

Can you confirm the pattern as provided in lecture material? YES NO (circle one)



2. a = 5 M = 17 (no constant term) seed = 1

Can you confirm the pattern as provided in lecture material? YES NO (circle one)



3. a = 43 M = 2048 (no constant term) seed = 1

For the following number of dots, indicate whether you think the output looks random by ticking √

(random) or crossing X (not random).



35

200

2048





4. a = 45 M = 2048 (no constant term) seed = 1

For the following number of dots, indicate whether you think the output looks random by ticking √

(random) or crossing X (not random).



35

200

2048



What is the smallest number of dots that need to be displayed to show the last plot? ____



5. a = 75 M = 6553 (no constant term) seed = 1 (Sinclair ZX Spectrum)

For the following number of dots, indicate whether you think the output looks random by ticking √

(random) or crossing X (not random).



300

1200

5000





6. Select the preset Grogono generator. Display 20,000 dots with a seed = 1. For the following values of

k, indicate whether you think the output looks random by ticking √ (random) or crossing X

(random).



k=1

k = 14

k = 38





7. Select the preset Park/Miller generator. Display 1,000,000 dots with a seed = 1. Vary k. What value

of k results in the generator output not looking random? ____





2

ALG0183 Algorithms and Data Structures









In a sequence of N random numbers:

The mean number of runs M is approximated by: (2N-1)/3 (= 15.66 for N = 24)

The variance of the number of runs V is approximated by: (16N-29)/90 (= 3.94 for N = 24)



Part B

Download the program RunsTest.java from the ALG0183 website. Compile and run it. The program

should produce a list of 500 calculations of the number of runs in a sequence of 24 randomly generated

numbers. Copy and paste this data into Excel. Using Data Analysis in Excel, calculate the descriptive

statistics. Make a note of them below:



Mean

Variance

Standard Deviation

Minimum

Maximum



Do the mean and variance match the values of 15.66 and 3.94 obtained from the using the formulae? If

not, why not? Write your answer(s) below.









Write your own program to produce a list of 500 calculations of the number of runs in a sequence of 24

randomly generated numbers. The sequences should be random permutations of the base sequence

{1..24}. You may or may not make use of Weiss´s Random.java. Copy and paste the output data into

Excel. Using Data Analysis in Excel, calculate the descriptive statistics. Make a note of them below:



Mean

Variance

Standard Deviation

Minimum

Maximum



Do the mean and variance match the values of 15.66 and 3.94 obtained from the using the formulae? If

not, why not? Write your answer(s) below.









3

ALG0183 Algorithms and Data Structures





import java.util.Random;



public class RunsTest {

static int count,loop; // loop variables

static Random rand; // random number generator

static int runs; // number of runs

static boolean direction; // up run or down run?

static int first, second, next; // to support calculation



public static void main(String[] args) {

rand = new Random(); // or new Random(some_seed_value)

// A 500 calculations of the number of runs.

for (loop = 1; loop second) direction = false;



for (count = 1; count next) {

runs++;

}

if (direction == false & second next) {

direction = false;

}

if (direction == false & second < next) {

direction = true;

}

// Update second

second = next;

}



//System.out.println();

System.out.println(runs);

}

}

}







4



Related docs
Other docs by ajizai
Resume 1.docx _20K_ - Student of Fortune
Views: 0  |  Downloads: 0
msg00000
Views: 0  |  Downloads: 0
Pre-Tax Return Calculator 2010-2011
Views: 0  |  Downloads: 0
Excel file - The GEO-3 Data Compendium
Views: 0  |  Downloads: 0
Cooperators Tests - ARS
Views: 0  |  Downloads: 0
2010101473142104
Views: 0  |  Downloads: 0
AJHL - Shawn Stewart Sales
Views: 0  |  Downloads: 0
OBLATES_ BROTHER CADFAEL AND ROME
Views: 1  |  Downloads: 0
DuaneChipKeeler_CV-Resume
Views: 0  |  Downloads: 0
AIT-2009-291-SC
Views: 0  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!