Linear congruential Generator (LCG) Parameters of Good Quality

Metadata:
Published: 2023-07-08
Last modified: 2024-02-24 (make table headings float so you can read the large table more easily)


Background

Multiplicative congruential generators (MCGs) and linear congruential generators (LCGs) are a common algorithm for implementing a pseudo-random random number generator (PRNG). They take the form of:
xn = axn−1 (mod m) (MCG)
xn = axn−1 + c (mod m) (LCG),
where x is the sequence of outputs (x0 is the so-called seed, which I assume is a term you are familiar with), a is the multiplier, c is the increment and m is the modulus.

In 1999, Pierre L’Ecuyer presented a paper entitled Tables of Linear Congruential Generators of Different Sizes and Good Lattice Structure that was published in volume 68(225) of Mathematics of Computation, pp. 249–260 (doi:10.1090/S0025-5718-99-00996-5). However, there have been significant errata affecting the most useful part, the tables of good MCG and LCG parameters. Neither are PDFs particularly accessible nor are errata obvious to find, so I will be summarizing the parts relevant for those who just want a working MCG or LCG.

There are two major kinds of generators that L’Ecuyer looked at: Those with prime m and those with m as a power of two. With prime m, no increment c is necessary. However, with m being a power of two—and for performance reasons this is often interesting—, the maximum period with no increment can be achieved with a = 5 (mod 8) for a period of m/4; by adding an (odd) increment c, you can get the full period of m. However, in any case, with an LCG with a modulus that is a power of two, you must use only the upper bits as the lower bits have a small period. Additionally, if using no increment, the seed must be odd with a power of two. In summary:

m is prime
no increment; difficult to make uniform random numbers out of
m is a power of two and using no increment
toss lower bits, ideally at least 32;
seed must be odd
m is a power of two and using increment
toss lower bits, ideally at least 32;
increment must be odd

For implementation reasons, only Mersenne primes and pseudo-Mersenne primes (2e − f, where f is very small [pseudo-Mersenne prime] or f = 1 [Mersenne prime]) are considered for prime moduli. Details on how to implement this are widely available.

I do not recommend using an LCG or MCG and instead suggest, wherever possible, the use of the xo(ro)shiro family or LXM generators. But practical necessity sometimes makes an LCG or MCG unavoidable.

Historical note: Guy L. Steele Jr. and Sebastino Vigna have presented a different set of multipliers and performed an exhaustive search for all numbers up to 35 bits in their paper Computationally easy, spectrally good multipliers for congruential pseudorandom number generators, published in volume 52(2) of Journal of: Software: Practice and Experience, pp. 443–458 (doi:10.1002/spe.3030). These seem preferable over L’Ecuyer’s multipliers as they could benefit from modern computational power to explore the search space. However, my post only provides the parameters in L’Ecuyer’s paper because the errata are numerous and significant, so using them without a consolidated list is inconvenient.

Tables incorporating the errata

In these tables, the M value roughly means whether the multipliers that are good for small, medium and large dimensions. The best M value in a class is emphasized. You generally want the one with the best for M32.

The a* value is the multiplicative inverse of a and generates the same sequence, just in reverse.

Table for prime m

Use xn = axn−1 (mod m).

Data also available as comma-separated values (CSV).

Table 1: Values for prime m
m a a* M8 M16 M32
28 − 5 33 213 0.70617 0.66083 0.64645
55 178 0.66973 0.66973 0.64645
29 − 3 35 160 0.68202 0.68202 0.63233
110 236 0.68202 0.68202 0.63233
273 399 0.68202 0.68202 0.63233
349 474 0.68202 0.68202 0.63233
210 − 3 65 377 0.69069 0.66317 0.61872
644 956 0.69069 0.66317 0.61872
211 − 9 995 1498 0.72170 0.65531 0.60549
328 603 0.69551 0.69189 0.60549
393 799 0.65283 0.65283 0.65283
212 − 3 209 3858 0.67296 0.60649 0.60649
235 3884 0.67296 0.60649 0.60649
352 500 0.64259 0.64259 0.64259
3593 3741 0.64259 0.64259 0.64259
213 − 1 884 7459 0.67317 0.61508 0.61508
1716 5580 0.64854 0.64854 0.64854
2685 6083 0.64854 0.64854 0.64854
214 − 3 572 13374 0.71968 0.59638 0.59638
3007 15809 0.71968 0.59638 0.59638
665 3424 0.71116 0.66792 0.65508
12957 15716 0.71116 0.66792 0.65508
215 − 19 219 30805 0.71802 0.56955 0.56955
1944 32530 0.71802 0.56955 0.56955
9515 10088 0.69372 0.67356 0.67356
22661 23234 0.69372 0.67356 0.67356
216 − 15 17364 32236 0.70713 0.44566 0.44566
33285 48157 0.70713 0.44566 0.44566
2469 47104 0.64650 0.63900 0.63900
217 − 1 43165 66284 0.70941 0.58409 0.58409
29223 119858 0.67169 0.67169 0.65617
29803 76704 0.66838 0.66230 0.66230
218 − 5 92717 166972 0.72539 0.61601 0.61601
21876 118068 0.67832 0.67832 0.67019
219 − 1 283741 358899 0.72130 0.59188 0.59188
37698 127574 0.66780 0.66780 0.65255
155411 157781 0.69573 0.66646 0.66646
220 − 3 380985 444362 0.71709 0.60387 0.60387
604211 667588 0.71709 0.60387 0.60387
100768 463964 0.66055 0.66055 0.60062
947805 584609 0.66055 0.66055 0.60062
22202 246298 0.66738 0.65888 0.65888
1026371 802275 0.66738 0.65888 0.65888
221 − 9 360889 1372180 0.72537 0.59108 0.59108
1043187 1352851 0.68608 0.68608 0.62381
1939807 1969917 0.68492 0.68492 0.67664
222 − 3 914334 1406151 0.72226 0.53547 0.53547
2788150 3279967 0.72226 0.53547 0.53547
1731287 2040406 0.67819 0.67819 0.67611
2463014 2153895 0.67819 0.67819 0.67611
223 − 15 653276 5169235 0.73407 0.65758 0.61581
3219358 7735317 0.73407 0.65758 0.61581
1706325 6513898 0.67462 0.67462 0.65778
6682268 1874695 0.67462 0.67462 0.65778
422527 5515073 0.67530 0.66916 0.66916
7966066 2873520 0.67530 0.66916 0.66916
224 − 3 6423135 9726917 0.74477 0.54337 0.54337
7050296 10354078 0.74477 0.54337 0.54337
4408741 6180188 0.66849 0.66849 0.66543
12368472 10597025 0.66849 0.66849 0.66543
931724 5637643 0.68149 0.66735 0.66735
15845489 11139570 0.68149 0.66735 0.66735
225 − 39 25907312 32544832 0.74982 0.58170 0.58170
12836191 5420585 0.69488 0.68447 0.57247
28133808 20718202 0.69488 0.68447 0.57247
25612572 1860625 0.67766 0.67105 0.66953
31693768 7941821 0.67766 0.67105 0.66953
226 − 5 26590841 11526618 0.76610 0.55995 0.55995
19552116 24409594 0.69099 0.69099 0.64966
66117721 6763103 0.68061 0.67408 0.67062
227 − 39 45576512 70391260 0.75874 0.58717 0.58717
63826429 88641177 0.75874 0.58717 0.58717
3162696 71543207 0.70233 0.67264 0.66714
228 − 57 246049789 150873839 0.74215 0.52820 0.52820
140853223 102445941 0.70462 0.67353 0.56023
29908911 166441841 0.67604 0.67353 0.58183
104122896 111501501 0.66326 0.65808 0.65808
229 − 3 520332806 219118189 0.75238 0.59538 0.59538
530877178 475905290 0.67352 0.67088 0.66418
230 − 35 771645345 599290962 0.74881 0.60540 0.59895
295397169 1017586987 0.68323 0.67420 0.52102
921746065 679186565 0.65830 0.65830 0.65830
231 − 1 1583458089 1132489760 0.72771 0.61996 0.61996
784588716 163490618 0.65885 0.65388 0.65388
232 − 5 1588635695 3870709308 0.74530 0.64199 0.64034
1223106847 4223879656 0.69299 0.67551 0.64034
279470273 1815976680 0.65862 0.65862 0.65862
233 − 9 7425194315 8436767804 0.73666 0.45155 0.45155
2278442619 1729516095 0.66244 0.65958 0.63549
7312638624 205277214 0.65221 0.65221 0.65221
234 − 41 5295517759 2447157083 0.73607 0.42784 0.42784
473186378 6625295500 0.66652 0.66652 0.65074
235 − 31 3124199165 27181987157 0.74740 0.55117 0.55117
22277574834 16353251630 0.68241 0.65471 0.61272
8094871968 31023073077 0.64471 0.64471 0.64471
236 − 5 49865143810 44525253482 0.72011 0.56045 0.56045
45453986995 40162435147 0.66038 0.65905 0.65665
237 − 25 76886758244 31450092817 0.73284 0.59222 0.55865
2996735870 105638438130 0.70849 0.65341 0.63328
85876534675 116895888786 0.66073 0.65085 0.65085
238 − 45 17838542566 234584904863 0.72311 0.59289 0.57131
101262352583 258824536167 0.65223 0.65035 0.60629
24271817484 141086538846 0.64022 0.64022 0.63644
239 − 7 61992693052 207382937966 0.72606 0.50283 0.50283
486583348513 247058793858 0.65522 0.64233 0.62267
541240737696 68317042802 0.64118 0.64118 0.64118
240 − 87 1038914804222 956569416632 0.73656 0.56206 0.56206
88718554611 864341149053 0.68083 0.67629 0.60506
937333352873 945467218816 0.69567 0.64693 0.64286
241 − 21 140245111714 1888116500887 0.72891 0.57568 0.57568
416480024109 1420814698317 0.65093 0.64692 0.61035
1319743354064 717943173063 0.65422 0.63748 0.63748
242 − 11 2214813540776 4365946432566 0.74418 0.62178 0.62178
2928603677866 3015630915308 0.66427 0.66427 0.62145
92644101553 626031856758 0.66812 0.65172 0.64110
243 − 57 4928052325348 4541763706392 0.73258 0.58054 0.58054
4204926164974 3434105419275 0.67015 0.65195 0.62862
3663455557440 2399767999928 0.65062 0.63552 0.63552
244 − 17 6307617245999 12680217534946 0.72095 0.40161 0.40161
11394954323348 6363281811747 0.64726 0.64726 0.61755
949305806524 12442836230635 0.64034 0.63577 0.63577
245 − 55 25933916233908 3608903742640 0.74020 0.48371 0.48371
18586042069168 11850386302026 0.66812 0.65288 0.57775
20827157855185 5870357204989 0.65174 0.63771 0.63771
246 − 21 63975993200055 63448138118203 0.74158 0.59455 0.59455
15721062042478 56602273662768 0.65292 0.65292 0.56919
31895852118078 30001556873103 0.65853 0.64391 0.63482
247 − 115 72624924005429 90086464761505 0.73939 0.61202 0.58428
47912952719020 65482710949587 0.66046 0.66046 0.57075
106090059835221 115067325755975 0.63210 0.63210 0.63210
248 − 59 49235258628958 253087341916107 0.74586 0.42596 0.42596
51699608632694 8419150949545 0.66302 0.64985 0.58435
59279420901007 163724808306782 0.65839 0.63595 0.63595
249 − 81 265609885904224 463134250989782 0.73506 0.53066 0.53066
480567615612976 545116409148737 0.65594 0.64246 0.57269
305898857643681 190965926304768 0.66333 0.63788 0.63577
250 − 27 1087141320185010 1051122009542795 0.72852 0.52208 0.52208
157252724901243 422705992136651 0.63912 0.63912 0.62044
791038363307311 605985299432352 0.64466 0.62837 0.62837
251 − 129 349044191547257 2128884970512414 0.73054 0.53683 0.53683
277678575478219 598269678776822 0.65501 0.64283 0.61820
486848186921772 1980113709690257 0.67181 0.63497 0.63497
252 − 47 4359287924442956 3707079847465153 0.72095 0.48117 0.48117
3622689089018661 290414426581729 0.68827 0.64482 0.60841
711667642880185 3319347797114578 0.63766 0.63067 0.63067
253 − 111 2082839274626558 3141627116318043 0.74842 0.49471 0.49471
4179081713689027 1169831480608704 0.64967 0.64102 0.59333
5667072534355537 7982986707690649 0.67430 0.63503 0.63503
254 − 33 9131148267933071 17639054895509756 0.71956 0.59136 0.59136
3819217137918427 6822546395505148 0.67456 0.65646 0.60358
11676603717543485 13197393252146039 0.66189 0.63663 0.63250
255 − 55 33266544676670489 11719476530693442 0.73046 0.61066 0.55598
19708881949174686 32182684885571630 0.65421 0.65091 0.61035
32075972421209701 15995561023396933 0.62948 0.62948 0.62948
256 − 5 4595551687825993 6128514294048584 0.72026 0.57724 0.57724
26093644409268278 69294271672288492 0.67840 0.66318 0.58207
4595551687828611 2389916809994467 0.64778 0.64243 0.62784
257 − 13 75953708294752990 66352637866891714 0.72732 0.57473 0.56026
95424006161758065 2274812368615087 0.64856 0.64856 0.59464
133686472073660397 113079751547221130 0.64588 0.62957 0.62957
258 − 27 101565695086122187 56502943171806276 0.77453 0.55885 0.55885
163847936876980536 256462492811829427 0.68047 0.66531 0.54314
206638310974457555 28146528635210647 0.64632 0.63406 0.63406
259 − 55 346764851511064641 287514719519235431 0.71819 0.54325 0.54325
124795884580648576 526457461907464601 0.64928 0.64760 0.62279
573223409952553925 81222304453481810 0.64258 0.63111 0.63111
260 − 93 561860773102413563 79300725740259852 0.72541 0.50786 0.50786
439138238526007932 998922549734761568 0.66098 0.65258 0.60350
734022639675925522 67273627956685463 0.66024 0.62375 0.62375
261 − 1 1351750484049952003 2078173049752560138 0.71028 0.54999 0.54276
1070922063159934167 212694642947925581 0.63769 0.63769 0.56108
1267205010812451270 1283839219676404755 0.63648 0.62092 0.62092
262 − 57 2774243619903564593 1983373718104285921 0.72982 0.61073 0.59560
431334713195186118 1159739479727509578 0.64966 0.64180 0.59560
2192641879660214934 2674546532986414750 0.62431 0.62374 0.62374
263 − 25 4645906587823291368 60091810420728157 0.73855 0.50741 0.50741
2551091334535185398 9006541669060512547 0.65169 0.64418 0.58261
4373305567859904186 6458928179451363983 0.62582 0.62582 0.62497
264 − 59 13891176665706064842 9044836419713972268 0.74105 0.36297 0.36297
2227057010910366687 17412224886468018797 0.68377 0.64579 0.52405
18263440312458789471 811465980874026894 0.63276 0.62970 0.62970
2127 − 1 82461096547334812307256211668490605096 33541844155669201573045277354985961133 0.74702 0.50027 0.50027
113783306134495484257537881325094815818 549754870954195569833520341422926719 0.63462 0.62590 0.56105
29590761937684265566924671478132826269 112488850895970220786062942797968665210 0.68766 0.62059 0.61214
2128 − 159 243267374564284687042667403923350539132 270208798174832049227011722299727468712 0.74262 0.56865 0.50100
55401819577318168010061270369451294976 169327211700629740391164723972852046130 0.64466 0.64466 0.51726
119682811202194777305538832478241040430 197801430676655477123612829371477088259 0.64289 0.62396 0.62396

Table for prime m and small multiplication result

Use xn = axn−1 (mod m).

This table gives parameters that ensure that the product of a multiplied by m − 1 is less than 253, allowing safe implementation with IEEE floating point numbers (e. g. JavaScript's sole number type). Values numbers of class for 227 and lower are not given as this constraint is also met by the prime m table above for all multipliers (except for a ≥ 67108883 for m = 227 − 39). No a* values are given, which would all be too great.

Data also available as comma-separated values (CSV).

Table 2: Values for prime m with 227 < m < 235 and a(m − 1) < 253
m a M8 M16 M32
228 − 57 31792125 0.75519 0.62442 0.61882
28932291 0.68564 0.67353 0.64453
18225409 0.68003 0.66230 0.66230
229 − 3 16538103 0.75238 0.59538 0.59538
3893367 0.69582 0.67168 0.62950
4723776 0.68494 0.66667 0.66418
5993731 0.67352 0.67088 0.66418
230 − 35 5122456 0.73967 0.59108 0.59108
4367618 0.70100 0.67634 0.59583
6453531 0.66184 0.65253 0.65253
231 − 1 1389796 0.72332 0.58994 0.57735
950975 0.67392 0.66519 0.60858
3467255 0.66306 0.65379 0.65379
232 − 5 657618 0.72484 0.47308 0.47308
93167 0.65996 0.65996 0.62613
1345659 0.65121 0.65121 0.65121
233 − 9 340416 0.74831 0.54269 0.54269
885918 0.66495 0.66295 0.65151
530399 0.67694 0.65619 0.65438
234 − 41 102311 0.72236 0.53661 0.53661
151586 0.65895 0.65355 0.56180
97779 0.67327 0.64581 0.64581
235 − 31 200105 0.70888 0.59919 0.59919
258524 0.64888 0.64749 0.60094
185852 0.65064 0.64725 0.64725

Table for m as a power of two and odd c

Use xn = axn−1 + c (mod m).

No a* values are given as the increment prevents the reverse sequence by just using a modular multiplicative inverse.

Data also available as comma-separated values (CSV).

Table 3: Values for m being a power of two and c being odd
m a M8 M16 M32
230 438293613 0.75107 0.58300 0.58300
523592853 0.70068 0.67686 0.64694
116646453 0.67718 0.67420 0.67107
231 37769685 0.75896 0.59146 0.59146
26757677 0.68312 0.68289 0.60858
20501397 0.67787 0.67787 0.66548
232 2891336453 0.75466 0.56806 0.56806
29943829 0.67429 0.67105 0.58062
32310901 0.65630 0.65336 0.65336
233 3766383685 0.75029 0.56952 0.56952
32684613 0.68055 0.67255 0.62595
5080384621 0.66619 0.66604 0.66604
234 52765661 0.74421 0.54539 0.54539
50004141 0.68442 0.67057 0.65570
67037349 0.69761 0.66579 0.66579
235 22475205 0.74676 0.51736 0.51736
15319397 0.67472 0.66933 0.60508
15550228621 0.65734 0.65552 0.65552
236 12132445 0.75179 0.52329 0.51602
8572309 0.66450 0.66389 0.64445
33690453 0.68461 0.65808 0.65760
240 330169576829 0.75723 0.46879 0.46879
42595477 0.67959 0.66436 0.63832
33261733 0.65941 0.65477 0.65477
248 181465474592829 0.75812 0.54668 0.54668
77596615844045 0.67653 0.66906 0.61130
10430376854301 0.66530 0.64759 0.64759
260 454339144066433781 0.75956 0.57465 0.57465
21828622668691829 0.65844 0.65566 0.63458
395904651965728677 0.63944 0.63944 0.63944
263 9219741426499971445 0.73715 0.54235 0.54235
2806196910506780709 0.69668 0.66519 0.60754
3249286849523012805 0.64507 0.63523 0.63523
264 2862933555777941757 0.75673 0.55283 0.54445
3202034522624059733 0.66164 0.66041 0.60256
3935559000370003845 0.67938 0.63763 0.63763
296 75564983892026345434470042133 0.74760 0.61011 0.61011
41898663544932533964435923957 0.64460 0.64460 0.54346
22104684854187731770179339485 0.65329 0.63558 0.63287
2128 47026247687942121848144207491837418733 0.74763 0.58508 0.57619
52583122484843402430317208685168068605 0.70223 0.65994 0.56182
47026247687942121848144207491837523525 0.64332 0.63077 0.62853

Table for m as a power of two c = 0

Use xn = axn−1 (mod m).

Avoid these generators; see above. Either use an increment or a prime modulus instead. For completeness relating to the original paper, I still list the values here.

Data also available as comma-separated values (CSV).

Table 4: Values for m being a power of two and c = 0
m a a* M8 M16 M32
230 177911525 285808365 0.74878 0.61693 0.61693
156051869 857580725 0.69501 0.67940 0.64413
143133861 770767661 0.69305 0.66791 0.66791
231 594156893 989142773 0.75913 0.50735 0.50735
558177141 1487707357 0.68978 0.68749 0.59450
602169653 448899357 0.67295 0.67116 0.67116
232 741103597 4109213157 0.75652 0.60751 0.60751
1597334677 851723965 0.70068 0.67686 0.64694
747796405 3425435293 0.66893 0.66001 0.66001
233 2185253333 173170557 0.75896 0.59146 0.59146
2174241325 3554448805 0.68312 0.68289 0.60858
2167985045 8162762685 0.67787 0.67787 0.66548
234 11481271045 16579283405 0.75466 0.56806 0.56806
4324911125 14504929085 0.67429 0.67105 0.58062
4327278197 7881103837 0.65630 0.65336 0.65336
235 8670442045 10790122773 0.75818 0.52727 0.52727
8622619205 31842912397 0.68055 0.67255 0.62595
22260253805 7113024869 0.66619 0.66604 0.66604
236 4092856269 31404866821 0.75662 0.50169 0.50169
17229873325 35216319269 0.68442 0.67057 0.65570
17246906533 12512050989 0.69761 0.66579 0.66579
248 49402601338917 75935939978157 0.75801 0.55089 0.55089
70189847242853 209773542181229 0.67618 0.66857 0.63609
21749276838573 136842555189541 0.65702 0.64692 0.64692
260 276137484736346373 672857982035536845 0.75277 0.48916 0.48916
150878991426218621 1108456478704721621 0.65527 0.65510 0.59498
271413322654087621 111008605039107341 0.64851 0.64851 0.64435
263 3512401965023503517 3753721746144068021 0.74926 0.50092 0.50092
2444805353187672469 2079243811257762237 0.70937 0.66091 0.61403
1987591058829310733 4007969225820588997 0.64490 0.64060 0.63994
264 1181783497276652981 13515856136758413469 0.76039 0.42672 0.42672
7664345821815920749 1865811235122147685 0.67778 0.66115 0.54884
2685821657736338717 6415128727920758069 0.65961 0.63932 0.63932
2128 25096281518912105342191851917838718629 310852368452748150078297415926143836461 0.76598 0.55122 0.54891
23766634975743270097972271989927654085 67836365537811707609274168323887561741 0.65708 0.65708 0.55662
92563704562804186071655587898373606109 297407245016942170064352095129111993717 0.63462 0.63462 0.63405