This preview shows page 1. Sign up to view the full content.
Unformatted text preview: alf of the multiply operations), this negative bit must be handled. One strategy to overcome this is to use a bit
mask to mask o the most signi cant bit. In this case, a logical AND operation should be
performed on the random, negative integer and the bit mask, imask=z'7fffffff', which
is a leading 0 followed by 31 ones (i.e. 011111111111111111111111111111112 ). This has the
e ect of the zeroing out the sign bit, forcing the number to be positive. Viz., Remarks
Table 3: Random Sequence of Example 3  LCG(5 0 37 1)
\Random" \Random" \Random"
n
Integer  Xn Binary  Xn Real  Xn
0
1
000001
0.0270
1
5
000101
0.1351
2
25
011001
0.6757
3
14
001110
0.3784
4
33
100001
0.8919
5
17
010001
0.4595
6
11
001011
0.2973
7
18
010010
0.4865
8
16
010000
0.4324
9
6
000110
0.1622
10
30
011110
0.8108
11
2
000010
0.0541
12
10
001010
0.2703
13
13
001101
0.3514
14
28
011100
0.7568
15
29
011101
0.7838
16
34
100010
0.9189
17
22
010110
0.5946
18
36
100100
0.9730
19
32
100000
0.8649
20
12
001100
0.3243
21
23
010111
0.6216
22
4
000100
0.1081
23
20
010100
0.5405
24
26
011010
0.7027
25
19
010011
0.5135
26
21
010101
0.5676
27
31
011111
0.8378
28
7
000111
0.1892
29
35
100011
0.9459
30
27
011011
0.7297
31
24
011000
0.6486
32
9
001001
0.2432 17 18
1 0 1 1 0 1 1 0 0 1 Xn = 730
mod IAND
0 0 0 0 1 0 1 1 1 1 MASK = 31
(31 = 25  1) 1 1 0 0 1 Xn = 25 =
0 0 0 0 0 Figure 5: Modulus Operation with m = 25 using IAND
xn = iand(xn, imask) However, masking works only when m is a power of two. Otherwise, it destroys the
sequence of numbers generated, and the theory no longer applies. In the general case, unless
the number resulting from the multiplication aXn ts in the register, special coding must
be done. An approach to this is to perform remaindering, by decomposing the multiply
operation into steps in which intermediate results are contained in 32 bits. This is the
strategy used by Park and Miller Park and Miller, 1988]. Note that, in the language C, one
can avoid the issue of the sign bit by using an unsigned integer. 3.3 Using Logical Masks to Perform Modulo 2M Operations
Generators where the modulus operation must be performed (requiring an integer division)
are more costly to implement than are those with moduli of 2M , where the integer division
and remaindering can be accomplished much more e ciently. We illustrate this as follows.
With a divisor of 2M , after the multiplication of aXn , the next seed is obtained simply by
performing a logical AND of Xn with a mask of (M ; 1) ones, rightjusti ed (see Figure
5). This is an extremely e cient operation on binary computers. Many computer languages
have a bitwise AND intrinsic function. Use of the AND operation also avoids the problem
with negative integers, discussed above. A FORTRAN implementation would look like:
xn = iand(xn, mask) 3.4 Summary of LCG Properties
Following Anderson Anderson, 1990], we summarize the salient features and the recommendations for three widely used types of linear, congruential random number generators. Remarks 19 Multiplicative, congruential generators are adequate to good for many applications. They are not acceptable... for highdimensional work. They can be very
good if speed is a major consideration. Prime moduli are best. However, moduli
of the form 2N are faster on binary computers. { Anderson (1990) m = 2M c > 0 :
The full period of m = 2M is obtained if and only if a 1 (mod 4), and c is odd
(often chosen as 1). Loworder bits are not random!
m = 2M c = 0 :
The maximum period of this generator is 2M ;2 (onequarter the modulus), and is
obtained if and only if a 3 (mod 8) or a 5 (mod 8) (5 is preferred) and the
initial seed is odd. Loworder bits are not random!
m = p (prime) c = 0 or c 6= 0 :
The maximum period of this generator is p ; 1 and is obtained if and only if a is a
primitive element modulo p. Note that there is always one integer which maps only
to itself. (In the case of c = 0, X0 = 0 maps to itself.) Loworder bits may or may
not be random! Park and Miller Park and Miller, 1988] recommend the following,
portable generator: m = p = 231 ; 1 (2 147 483 647), a = 16 807, and c = 0. The
code random.f, based upon Park and Miller's algorithm, is supplied with this package.
Note that, even when c is nonzero, the maximum period of this generator is still one
less than the modulus. Exercise 4  to establish all cycles in LCGs when m = p, a prime Consider linear, congruential random number generators. If c = 0, it is obvious that X0 = 0
is not a good candidate integer for the initial seed because it maps to itself. In fact, if m = p,
a prime, then there is always a number which maps to itself (a constant sequence), even if
c 6= 0. Prove this by nding the integer which maps to itself, and which does not appear in
the full period sequence of length m ; 1 for the following linear, congruential generators:
(a) LCG(5 0 37 X0 )
(b) LCG(5 1 37 X0 )
(c) LCG(5 5 37 X0 ) Exercise 5  exploring all possible sequences in simple LCGs For the linear, congruential genera...
View
Full
Document
This document was uploaded on 01/28/2014.
 Fall '14

Click to edit the document details