Parameters in Common Use
The most efficient LCGs have an m equal to a power of 2, most often m = 232 or m = 264, because this allows the modulus operation to be computed by merely truncating all but the rightmost 32 or 64 bits. The following table lists the parameters of LCGs in common use, including built-in rand functions in runtime libraries of various compilers.
Source | m | a | c | output bits of seed in rand / Random(L) |
---|---|---|---|---|
Numerical Recipes | 232 | 1664525 | 1013904223 | |
Borland C/C++ | 232 | 22695477 | 1 | bits 30..16 in rand, 30..0 in lrand |
glibc (used by GCC) | 231 | 1103515245 | 12345 | bits 30..0 |
ANSI C: Watcom, Digital Mars, CodeWarrior, IBM VisualAge C/C++ | 231 | 1103515245 | 12345 | bits 30..16 |
Borland Delphi, Virtual Pascal | 232 | 134775813 | 1 | bits 63..32 of (seed * L) |
Microsoft Visual/Quick C/C++ | 232 | 214013 (343FD16) | 2531011 (269EC316) | bits 30..16 |
Microsoft Visual Basic (6 and earlier) | 224 | 1140671485 (43FD43FD16) | 12820163 (C39EC316) | |
RtlUniform from Native API | 231 − 1 | 2147483629 (7FFFFFED16) | 2147483587 (7FFFFFC316) | |
Apple CarbonLib | 231 − 1 | 16807 | 0 | see MINSTD |
MMIX by Donald Knuth | 264 | 6364136223846793005 | 1442695040888963407 | |
Newlib | 264 | 6364136223846793005 | 1 | bits 63...32 |
VAX's MTH$RANDOM, old versions of glibc | 232 | 69069 | 1 | |
Java's java.util.Random | 248 | 25214903917 | 11 | bits 47...16 |
LC53 in Forth | 232 − 5 | 232 − 333333333 | 0 |
As shown above, LCGs do not always use all of the bits in the values they produce. For example, the Java implementation operates with 48-bit values at each iteration but returns only their 32 most significant bits. This is because the higher-order bits have longer periods than the lower order bits (see below). LCGs that use this truncation technique produce statistically better values than those that do not.
Read more about this topic: Linear Congruential Generator
Famous quotes containing the words parameters and/or common:
“Men have defined the parameters of every subject. All feminist arguments, however radical in intent or consequence, are with or against assertions or premises implicit in the male system, which is made credible or authentic by the power of men to name.”
—Andrea Dworkin (b. 1946)
“If we dreamed the same thing every night, it would affect us much as the objects we see every day. And if a common workman were sure to dream every night for twelve hours that he was a king, I believe he would be almost as happy as a king who should dream every night for twelve hours on end that he was a common workman.”
—Blaise Pascal (16231662)