{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $m \\ge 2$ be an integer, the modulus, and let $a$, $c$ and $X_0$ be integers with $0 \u003c a \u003c m$, $0 \\le c \u003c m$ and $0 \\le X_0 \u003c m$.\nThe *linear congruential generator* with multiplier $a$, increment $c$ and seed $X_0$ is a [[pseudorandom number generator|C5FG6ARWVV]].\nIts state space is $\\set{0, \\ldots, m-1}$ and its states are\n$$X_{n+1} = (a X_n + c) \\bmod m, \\qquad n \\ge 0,$$\nwhere $\\bmod$ is the [[modulo operation|03BR7SAX0Q]].\nIts outputs are the numbers $u_n = X_n / m \\in [0, 1)$.\nIf $c = 0$ it is called a *multiplicative* congruential generator, or Lehmer generator.\n\n## Remarks\n\nExample: $m = 8$, $a = 5$, $c = 1$, $X_0 = 0$.\nThe states are $0, 1, 6, 7, 4, 5, 2, 3, 0, \\ldots$, for instance $5 \\cdot 7 + 1 = 36 \\equiv 4 \\pmod 8$; all $8$ residues appear, so the period is $m$.\nNon-example: $X_{n+1} = X_n^2 \\bmod m$ is not a linear congruential generator, because the map $x \\mapsto x^2$ is not of the form $x \\mapsto ax + c$.\nThe map $x \\mapsto ax + c$ is an affine map of the ring of [[integers modulo $m$|03VFZ2WETT]], so the period is at most $m$.\nThe Hull–Dobell theorem treats $c \\ne 0$.\nThe period equals $m$ for every seed if and only if three conditions hold.\nThey are: $c$ and $m$ are coprime, every prime factor of $m$ divides $a - 1$, and $4$ divides $a - 1$ if $4$ divides $m$.\nIn the example, $\\gcd(1, 8) = 1$ and $a - 1 = 4$, so the conditions hold.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "defines": "Q0K15AWV8H",
    "kind": "definition",
    "msc": [
      "65C10",
      "11K45"
    ],
    "name": "Linear congruential generator",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Linear_congruential_generator"
      }
    ],
    "tag": "3MDPTW005V",
    "uses": [
      "C5FG6ARWVV",
      "03BR7SAX0Q",
      "03VFZ2WETT"
    ]
  },
  "kind": "definition",
  "link": "https://tamnd.github.io/math2/node/3MDPTW005V/",
  "links": [
    {
      "field": "defines",
      "target": "Q0K15AWV8H"
    },
    {
      "field": "uses",
      "target": "C5FG6ARWVV"
    },
    {
      "field": "uses",
      "target": "03BR7SAX0Q"
    },
    {
      "field": "uses",
      "target": "03VFZ2WETT"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/3MDPTW005V.md",
  "msc": [
    "65C10",
    "11K45"
  ],
  "name": "Linear congruential generator",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/3MD/3MDPTW005V.md",
  "status": null,
  "tag": "3MDPTW005V",
  "uri": "m2://3MDPTW005V",
  "url": "https://tamnd.github.io/math2/wiki/linear-congruential-generator-definition/",
  "writing": {
    "tag": "3MDPTW005V",
    "kind": "definition",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
