Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Linear congruential generator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Algorithm for generating pseudo-randomized numbers}} [[File:Linear_congruential_generator_visualisation.svg|thumb|480px|Two modulo-9 LCGs show how different parameters lead to different cycle lengths. Each row shows the state evolving until it repeats. The top row shows a generator with ''m'' = 9, ''a'' = 2, ''c'' = 0, and a seed of 1, which produces a cycle of length 6. The second row is the same generator with a seed of 3, which produces a cycle of length 2. Using ''a'' = 4 and ''c'' = 1 (bottom row) gives a cycle length of 9 with any seed in [0, 8].]] A '''linear congruential generator''' ('''LCG''') is an [[algorithm]] that yields a sequence of pseudo-randomized numbers calculated with a discontinuous [[piecewise linear function|piecewise linear equation]]. The method represents one of the oldest and best-known [[pseudorandom number generator]] algorithms. The theory behind them is relatively easy to understand, and they are easily implemented and fast, especially on computer hardware which can provide [[modular arithmetic]] by storage-bit truncation. The generator is defined by the [[recurrence relation]]: :<math>X_{n+1} = \left( a X_n + c \right)\bmod m</math> where <math>X</math> is the [[sequence]] of pseudo-random values, and : <math> m,\, 0<m </math> β the "[[modulo operation|modulus]]" : <math> a,\,0 < a < m</math> β the "multiplier" : <math> c,\,0 \le c < m</math> β the "increment" : <math> X_0,\,0 \le X_0 < m</math> β the "seed" or "start value" are [[integer]] constants that specify the generator. If ''c'' = 0, the generator is often called a '''multiplicative congruential generator''' (MCG), or [[Lehmer RNG]]. If ''c'' β 0, the method is called a '''mixed congruential generator'''.{{r|KnuthV2|p=4-}} When ''c'' β 0, a mathematician would call the recurrence an [[affine transformation]], not a [[Linear transformation|linear]] one, but the misnomer is well-established in computer science.<ref name=Steele20>{{cite journal |title=Computationally easy, spectrally good multipliers for congruential pseudorandom number generators |first1=Guy L. Jr. |last1=Steele |author-link1=Guy L. Steele Jr. |first2=Sebastiano |last2=Vigna |author-link2=Sebastiano Vigna |journal=Software: Practice and Experience |volume=52 |issue=2 |date=February 2022 |pages=443β458 |doi=10.1002/spe.3030 |doi-access=free |arxiv=2001.05304 |hdl=2434/891395 |orig-date=15 January 2020 |url=https://www.researchgate.net/publication/354960552 |quote=these denominations, by now used for half a century, are completely wrong from a mathematical viewpoint.... At this point it is unlikely that the now-traditional names will be corrected. }} Associated software and data at https://github.com/vigna/CPRNG.</ref>{{Rp|1}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)