Loading [MathJax]/extensions/TeX/boldsymbol.js

 

 

 

Random number generator RNG, RAN0

The term [N_{i-1}/q]r is always smaller or equal N_{i-1}(r/q) and with r < q we obtain always a number smaller than N_{i-1} , which is smaller than M . And since the number N_{i-1}\mathrm{MOD} (q) is between zero and q-1 then a(N_{i-1}\mathrm{MOD} (q)) < aq . Combined with our definition of q=[M/a] ensures that this term is also smaller than M meaning that both terms fit into a 32-bit signed integer. None of these two terms can be negative, but their difference could. The algorithm below adds M if their difference is negative. Note that the program uses the bitwise \oplus operator to generate the starting point for each generation of a random number. The period of ran0 is \sim 2.1\times 10^{9} . A special feature of this algorithm is that is should never be called with the initial seed set to 0 .