# If we desire rn to be distributed on 0 1 then we

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ws: Xn Xn Rn = oat(m) or Rn = oat(m ; 1) When dividing by m, the Rn values are then distributed on 0,1). If we desire Rn to be distributed on 0, 1], then we would divide by (m ; 1). We desire uniformity, where any particular Rn is just as likely to appear as any other Rn, and the average of the Rn is very close to 0.5. Example 1 LCG (5, 1, 16, 1) Let us consider a simple example with a = 5, c = 1, m = 16, and X0 = 1. The sequence of pseudorandom integers generated by this algorithm is: 1,6,15,12,13,2,11,8,9,14,7,4,5,10,3,0,1,6,15,12,13,2,11,8,9,14,: : : In Figure 3, we illustrate the random number cycle for this generator. We immediately observe four features: The period (the number of integers before the sequence repeats) P is 16 - exactly equal to the modulus, m. When the next result depends upon only the previous integer, the longest period possible is P = m. In the current example with a modulus of 16, the mod operation generates integer results from 0 to 15, inclusive. Thus, for m = 16, this sequence is of long period (the longest possible), and uniform (it completely lls the space of integers from 0-15). Note that the period is exactly equal to 24, i.e. 2M , where M is the base 2 log of the modulus. This particular sequence exhibits throughout its period the pattern of alternating odd and even integers. It is frequently instructive to view this sequence in binary and then after performing a real division by m to result in random real numbers (see Table 1). It is readily apparent that the sequence is serially correlated. In fact, note that the right-most binary digit exhibits the regular pattern 1 0 1 0 : : :. Due to this lack of 12 Initial Seed ● ● 0 ● 1 6 ● 3 ● ● ● 15 12 10 5 13 4 ● Clockwise Traversal ● 2 11 7 14 ● 9 8 ● ● ● ● ● ● Figure 3: Random Number Cycle for Example 1- LC(5,1,16,1) randomness, the Xn values should not be used as random digits (especially the rightmost digits of Xn ). In fact, this lack of randomness results from using a power of two for m. Despite this, a modulus which is a power of two is often used, for this renders the process of performing the modulus operation very e cient. Moreover, the real numbers generated from the integer sequence are generally su ciently random in the higher order (most signi cant) bits to be used in many application codes. Next, we infer the following. Because each random integer results from the previous integer alone, selecting any initial seed from 0 to 15 would just cyclically shift the above sequence. We could begin anywhere on the random number cycle, and we would proceed clockwise around the random number cycle from that starting point. Thus, all that a di erent choice of the initial seed does is shift the starting point in the sequence already determined by a, c and m. Finally, we note that the average of the real numbers is 0.4688 and the variance is 0.0830. The departure of these values from the ideal ones of 1/2 and 1=12 0:08333 is due to the short period of this sequence and the rather coarse resolution of the generated real numbers. These conditions of average and variance approaching the theoretical values are necessary but not su cient conditions for a good random number generator. Let us exercise the code ranlc.f for additional parameters. In so doing, we shall choose parameters that illustrate speci c aspects of linear, congruential generators. First, we take the case of c = 0. This is termed a multiplicative congruential random number generator: Remarks 13 Table 1: Random Sequence of Example 1 - LCG(5 1 16 1) \Random" \Random" \Random" n Integer - Xn Binary - Xn Real - Xn 0 1 0001 0.0625 1 6 0110 0.3750 2 15 1111 0.9375 3 12 1100 0.7500 4 13 1101 0.8125 5 2 0010 0.1250 6 11 1011 0.6875 7 8 1000 0.5000 8 9 1001 0.5625 9 14 1110 0.8750 10 7 0111 0.4375 11 4 0100 0.2500 12 5 0101 0.3125 13 10 1010 0.6250 14 3 0011 0.1875 15 0 0000 0.0000 Average 0.4688 Variance 0.0830 Xn+1 = aXn (mod m) The case c 6= 0 is termed a mixed congruential random number generator. (1) Example 2 LCG (5, 0, 16, 1) As illustrated in Figure 4, we obtain the sequence 1,5,9,13,1,5,9,13,: : : Note that we now have a period, P , of only 4 | this is 1/4 the modulus. In fact, when m is a power of 2 (here, 2M = 24) and c = 0, the maximum period is 2M ;2. Here again, we note that the low order bits are not random. In fact, the two least signi cant bits 14 Initial Seed ● Clockwise Traversal 1 ● 13 5 ● 9 ● Figure 4: Random Number Cycle for Example 2{ LCG(5,0,16,1) are constant, always 01 and the most signi cant bits are quasi-random, exhibiting the pattern 00, 01, 10, and 11 Also, the sequence is correlated, as all successive integers di er by 4 from their predecessors. At coarse granularity, the sequence is uniform. For example, if we divide 0,1) equally into quarter segments, then exactly one random number falls into each segment: 0, 0.25), 0.25, 0.5), 0.5, 0.75) and 0.75,1). However, at ner granularity, this uniformity breaks down - consider dividing up the domain into 8 equal segments, for example. Here, we have a mismatch between the random number generator we are using, and the \...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online