Random Number Generation � Handout #12 (Note HW!)

 

So, we've learned that the behavior of a system can be characterized by two things:� the interarrival time distribution and the service time distribution (given that the arrivals and servicing are independent and identically distributed).� With a computer program simulation, we may have to rely on random numbers to test the simulation.

 

We know though that a computer's memory is finite and that only a certain range of numbers can be generated.� For example if integers on a certain computer are 16-bits long (assume without using exponents and negative numbers), then we can only generate 216 numbers, or 65536 numbers.� How then do we select from this range so that we get random numbers?

 

We can't get "real" random numbers!

 

We have to use techniques to get pseudo-random numbers.

 

We know that we can generate integers in some range.

Let i = {���������������������������������������������� }

Let Xi be the integers generated.

Let m be a positive integer.

Let 1..m-1 be the range of integers generated.

 

Then we know:

Ri = Xi/m

lies between ���������������������������� �and ���������������������������� .

 

For example, let the number of bits that represent positive integers be 16 as above.� Then:

{��������������������������������� } is the range of numbers generated

m �1 = �����������������������������������

m = ����������������������������������������

So, we see that R lies between 0 and 1.

R1 = X1/m = 1/65537 = 1.525855623541e-5

R2 = X2/m = 2/65537 = 3.051711247082e-5

M

R1000 = X1000/m = 1000/65537 = 0.01525855623541

M

R10000 = X10000/m = 10000/65537 = 0.1525855623541

M

R65534 = X65534/m = 65534/65537 = 0.9999542243313

R65535 = X65535/m = 65535/65537 = 0.9999694828875

R65536 = X65536/m = 65536/65537 = 0.9999847414438

Thus,

Ri = {1.525855623541e-5�0.9999847414438}

 


Given these numbers, how do we make a random sequence Ri?

 

A sequence of random numbers R1, R2, �., must have two statistical properties:

1.      ����������������������������������������� .� Random numbers must be selected from a continuous uniform distribution between zero and one.

2.      ����������������������������������������� .� The choice of one random number does not affect the choice of another.

 

Midsquare Method

Let:

X0:� initial seed

Xi = middle digits ( (Xi-1)2 )

Ri = Xi (10-#middle digits)

 

Example:

X0 = 151

middle digits are 103, 102, and 101 places

 

X1 => (151)2 = 22801 => ������������������������������������������

R1 = ��������������������������� �(10-3) = ���������������������������������

X2 => (����������������������� )2 = 78400 => 840

R2 = 840 (10-3) = 0.84

X3 => (840)2 = 705600 => 560

R3 = 560 (10-3) = 0.56

�

 

Midproduct Technique

Let:

X0', X0: initial seeds with same number of digits, D.

U1 = ( X0' ) ( X0 )

X1 = D middle digits ( (U1) )

R1 = X1 (10-D)

Continue with U2 = ( X0 ) ( X1 )

Example:

X0' = 151, X0 = 780

U1 = ( X0' ) ( X0 ) = (151)(780) = 117780

X1 = ���������������������������

R1 = ���������������������������

U2 = ( X0 ) ( X1 ) = (780)(������������������������������� ) = 606840

X2 = 684

R2 = 0.684

�

 


Linear Congruential Method

Another way is a simple recurrence relation:

Xi = a � Xi-1� + c (mod m)

Ri = (Xi)/m

where,

a � constant multiplier:� positive integer, and

c � increment:� non-negative integer, and

m � modulus:� positive integer, and

X0 � starting seed: positive integer.

 

When ������������������������������������� , the Linear Congruential Method is called the Multiplicative Congruential Method, and when ����������������������������������� , it is called the Mixed Congruential Method.

 

Note that the numbers generated from Xi = a � Xi-1� + c (mod m) can only take on the values:

{0, 1, 2, �, m-1}

and that the random numbers generated from Ri = (Xi)/m can only take on the values,

I = {0, 1/m, 2/m, �, (m-1)/m}

Therefore, each Ri is ��������������������������������������� �on I, not �������������������������������������������� .� This will be acceptable if m is very large.���

 

Example:

a = 7, c = 23, m = 8, X0 = 1.

 

What is the range of possible numbers?� {�������������������������������������������������������� }

Xi = 7 � Xi-1� + 23 (mod 8)

Ri = (Xi)/8

 

i

7 � Xi-1� + 5 (mod 8)

Xi

Ri

0

-

1

0.125

1

7 � 1 + 23 (mod 8) = 30 mod 8

6

0.75

2

7 � 6 + 23 (mod 8) = 65 mod 8

2

0.25

3

7 � 2 + 23 (mod 8) = 37 mod 8

5

0.625

4

7 � 5 + 23 (mod 8) = 58 mod 8

2

0.25

�

Sequence repeats!

�

�

 

This sequence is cyclic with period equal to ����������������������������������������� �repeats.

 


Kobayashi's example:

a = 13, c = 10, m = 10, X0 = 2.

What is the range of possible numbers?� {�������������������������������������������������������� }

Xi = 13 � Xi-1� + 10 (mod 10)

 

i

13 � Xi-1� + 10 (mod 10)

Xi

0

-

2

1

13 � 2� + 10 (mod 10) = 26 mod 10

6

2

13 � 6� + 10 (mod 10) = 88 mod 10

8

3

13 � 8� + 10 (mod 10) = 114 mod 10

4

4

13 � 4� + 10 (mod 10) = 62 mod 10

2

5

13 � 2� + 10 (mod 10) = 26 mod 10

6

�

Sequence repeats!

�

This sequence is also cyclic and has a period of ����������������������������������������������������������� .

 

We need to be careful about choices of a, c, m, and X0 or we'll get a small period.� We would like the period to be close to ����������������������������������������������� �(a full cycle period).

 

To obtain the largest period possible for m equal to a power of two we need:

m = 2b

c = relatively prime to m

a = 1 + 4k, where k is an integer.

The longest possible period then is P = m = 2b.

 


Multiplicative Congruential Method

Let c = 0, then we have a Multiplicative Congruential Method:

Xi = a � Xi-1 (mod m)

where,

a:� positive integer, and

m:� positive integer, and

X0:� starting seed.

 

The longest period for the multiplicative congruential method for m a power of two (m = 2b), is:

P = m/4 = mb-2.

This occurs when:

m = 2b, c = 0, a = �3 + 8k, where k is an integer, and, X0 = an odd integer.

 

A good Mulitplicative Congruential Generator is one where the period is ���������������������������������� .� A way to achieve this is when:

m = 2pe, where p is an odd prime number and e is a positive integer.

a is a primitive root of m.

X0 is relatively prime to m.

 

Lewis, Goodman, & Miller (1969), page 237 Kobayashi and page 266 Banks:

m = 231 � 1 (which happens to be a prime number)

ak = 75

Xi = 75 Xi-1 (mod 231 � 1)

Then,

P = m � 1, which is over ���������������������������������������������������������

 

 

 

Homework:� Answer the following two questions:

 

  1. Using the multiplicative method, set m = 32, and a = 3.� What is the period if the seed Z0 is an odd number?� Find the sequence when Z0 = 1.� Do the same for Z0 = 5.� What will happen if an even number is chosen as a seed?
  2. Using the mixed congruential method, set m = 32, a = 5, and c = 3.� What is the period of the resultant sequence?� Generate the sequence with Z0 = 2.

 

Due Tuesday, November 4, 2003.