10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8.2 Random-number generation 399<br />

Algorithm 8.2.2 (32-bit random-number generator (Knuth, Lewis)).<br />

This algorithm provides seeding and random functions for a certain generator<br />

known to have fairly good statistical behavior. We take M =2 32 as the generator<br />

modulus, and will speedily effect operations modulo M by logical “and” (&)<br />

with M −1. One first calls the seed() procedure, then calls random() successively<br />

to get random numbers.<br />

1. [Procedure seed]<br />

seed() {<br />

Choose starting seed x; // x is an integer in [0,M − 1].<br />

return;<br />

}<br />

2. [Function random]<br />

random() {<br />

x = (1664525x + 1013904223) & (M − 1);<br />

return x; // New random number.<br />

}<br />

Note that the “and” operation with M − 1 is simply the taking of the low 32<br />

bits of the number involved. Along similar lines, the popular generator<br />

xn+1 = (16807xn) modM31,<br />

where M31 =231 − 1 is a Mersenne prime, has enjoyed a certain success in<br />

passing many (but not all) experimental tests [Park and Miller 1988], [Press<br />

et al. 1996].<br />

An interesting optimization of certain congruential generators has been<br />

forwarded in [Wu 1997]. The recursion is<br />

xn+1 = (2 30 − 2 19 <br />

)xn mod M61,<br />

where the fact of M61 being a Mersenne prime allows some rapid arithmetic.<br />

Algorithm 8.2.3 (Fast, 61-bit random generator). This algorithm provides<br />

seeding and random functions for the Wu generator, modulus M =2 61 − 1 and<br />

multiplier c =2 30 − 2 19 . Though modular multiplications occur in principle, the<br />

explicit operations below are relegated to addition/subtraction, left/right shifts<br />

(>, respectively), and logical “and” (&) which acts as a certain mod<br />

operation.<br />

1. [Procedure seed]<br />

seed() {<br />

Choose starting seed x; // x is an integer in [1,M − 1].<br />

return;<br />

}<br />

2. [Function random]<br />

random() {<br />

x =(x>>31) + ((x 42) − ((x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!