{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

There are two separate issues to consider here the

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: scale" or granularity of our problem | the RNG is incapable of producing random numbers which ll our attribute space (here, our 8 bins). There are two separate issues to consider here. The least troublesome is the nite precision existing in all computers, which results in a round-o error to the precision with which integers can be represented, or with which the oating point divide is accomplished. More serious is the second issue: the interaction of the sequence of random numbers produced by our generator with our application. This interaction is particularly troublesome when our application requires n-tuples of random numbers, instead of just one random number at a time. Later, we shall illustrate this e ect by displaying plots of individual points generated using various RNGs. In some applications, several random numbers are needed at a time. For example, when tracing particles among surfaces, three random numbers are required to obtain outgoing direction (one for outgoing azimuthal angle, and one for outgoing polar angle) and energy (usually, only one is required to obtain Remarks 15 Table 2: Random Sequence of Example 2 - LCG(5 0 16 1) \Random" \Random" \Random" n Integer - Xn Binary - Xn Real - Xn 0 1 0001 0.0625 1 5 0101 0.3125 2 9 1001 0.5625 3 13 1101 0.8125 Average 0.4375 Variance 0.0781 the energy). Example 3 LCG (5, 0, 37, 1) We obtain the sequence 1,5,25,14,33,17,11,18,16,6,30,2,10,13,28,29,34,22, 36,32,12,23,4,20,26,19,21,31,7,35,27,24,9,8,3,15, : : : Table 3 provides the sequence throughout the period. Here, because we use a prime number as the divisor for the modulus operation and c = 0, we obtain a period one less than modulus 37 (0 is not possible, as it maps to itself, so we obtain a period of 36). Indeed, when m = p, a prime, the maximum period, Pmax , is m ; 1, even if c 6= 0. Thus, for linear, congruential generators with a prime modulus, using a non-zero c does not increase the period. Here, the low order bits, while not exhibiting a discernible pattern, do not appear as \random" as one might expect. Indeed, as is shown in Altman Altman, 1988], the bitwise randomnes properties of LCGs should be considered on a case by case basis. He provides examples of LCGs with prime moduli that fail bitwise testing, but points out, for example, that LCG(13445 0 231 ; 1 X0 ) does pass the bitwise randomness test. Exercise 3 - to illustrate the generation of random numbers using LCG(13445, 0, 65536, 16811) and to partition the random real numbers into bins Obtain and edit the linear congruential program ranlc.f. Supply the additional code to compute the average and the variance. For sample sizes of 10, 100, 1,000, and 10,000, run the code and plot the errors in the average and variance versus sample size. Discuss how the error in these quantities varies with the sample size. Use the following parameters: a = 16807, c = 0, and m = 216(= 65536). 16 3.2 Initial Seed Now, we address establishing the initial seed. When debugging, it is important to implement the algorithm to reproduce the same stream of random numbers on successive runs. If the run is a debug run (noted, perhaps, by a parameter in the input le), the seed should be set to a constant initial value, such as a large prime number (it should be odd, as this will satisfy period conditions for any modulus). Otherwise, the initial seed should be set to a \random" odd value. Anderson 1990] recommends setting the initial seed X0 to the following integer: X0 = iyr + 100 (imonth ; 1 + 12 (iday ; 1 + 31 (ihour + 24 (imin + 60 isec)))) where the variables on the right-hand side are the integer values of the date and time. Note that the year is 2 digits long, i.e. the domain of iyr is 0 99]. However, we have found it preferable to introduce the maximum variation in the seed into the least signi cant bits by using the second of this century, rather than the most signi cant bits. Ergo, we prefer the following: X0 = isec + 60 (imin + 60 (ihr + 24 (iday ; 1 + 31 (imon ; 1 + 12 iyr)))) and, to ensure X0 is odd (in FORTRAN): x0 = ior(x0 1) Arithmetical Considerations Over ow and Negative Integers Consider performing the operation aXn + c (mod m). A large value of a is desirable to provide su cient randomness. A large value of m is also desired, so that the period is kept long. For example, on 32 bit computers, a and m are often 31 bits long, as the most signi cant bit (the 32nd bit) is generally used to indicate sign. When two 31 bit integers are multiplied together, a possibly 62 bit integer results. Thus, an over ow almost always occurs. Fortunately, oating point multipliers (and software emulations thereof) are designed to throw away the most signi cant bits, and retain the least signi cant 32 bits. However, if the result of the multiplication is so as to have the most signi cant bit (the 32nd bit) set, then the computer may treat this as a negative integer, which is incompatible with the algorithm above. If this happens (it occurs during one-h...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online