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)
“A person of definite character and purpose who comprehends our way of thought is sure to exert power over us. He cannot altogether be resisted; because, if he understands us, he can make us understand him, through the word, the look, or other symbol, which both of us connect with the common sentiment or idea; and thus by communicating an impulse he can move the will.”
—Charles Horton Cooley (18641929)