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:
“What our children have to fear is not the cars on the highways of tomorrow but our own pleasure in calculating the most elegant parameters of their deaths.”
—J.G. (James Graham)
“The moment the very name of Ireland is mentioned, the English seem to bid adieu to common feeling, common prudence, and common sense, and to act with the barbarity of tyrants, and the fatuity of idiots.”
—Sydney Smith (17711845)