Database Reference
In-Depth Information
random number generator (LCRNG). This generator has a very simple
implementation, as seen in the following code snippet, where m , a , and c are
constants that depend on the programming language:
public class LCRNG {
long x = System. currentTimeMillis ();
long a,c,m;
public LCRNG(long a,long c,long m) {
this.a = a;this.c = c;this.m = m;
}
public long next() {
x = (a*x + c) % m;
return x;
}
}
This generator is clearly very easy to implement. Because it consists of only
three operations, it is also quite fast. It is also not very good for statistical
applications. Properly called pseudo-random number generators (if the
starting value is known the entire sequence of random numbers can be
regenerated—this is actually useful when testing random algorithms), all
algorithmic generators display a periodic behavior of varying length. For the
LCRNG , the period is quite short, and possibly very short, for the low order
bits of the random number. For example, if m is a power of two, the LCRNG
produces alternating odd and even numbers, which is useful for winning bar
bets but not much else.
To overcome this, most implementations use only the high order bits of the
LCRNG .Java,forexample, uses48bitsofstateinitsdefaultrandomnumber
generator, butonlyreturns32ofthose48bits.Thisallowsittodropsomeof
the very short period low order bits. Unless the application is very memory
constrained, such as an embedded system, a better solution is to use a better
random number generator. One of the most popular generators available
is the Mersenne Twister algorithm. This algorithm is the default for the R
statistical programming language as well as MATLAB. It is not suitable for
cryptographic applications, since observing a sufficiently large number of
values from the generator allows for the prediction of future values, like the
LCRNG. However, the number of values required is sufficiently large that it
is good enough for most statistical applications.
Search WWH ::




Custom Search