{
  "schemaVersion": 1,
  "slug": "random-number-generator",
  "category": "gaming",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "b122587d378fedae356c710e808c1c4cb7e32c654b9502b01df8d7f9841871a8",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/random-number-generator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "a_{i+1} = (a_i + 0x6D2B79F5) mod 2³²; u_i = (t_i ⊕ (t_i ≫ 14) mod 2³²) ÷ 2³²; x_i = lo + ⌊u_i×(hi−lo+1)⌋",
    "vars": [
      [
        "a_i",
        "PRNG state, a₀ = seed"
      ],
      [
        "u_i",
        "Uniform draw in [0,1)"
      ],
      [
        "lo",
        "Lower bound"
      ],
      [
        "hi",
        "Upper bound"
      ],
      [
        "x_i",
        "Generated integer"
      ],
      [
        "t_i",
        "Intermediate 32-bit word"
      ],
      [
        "i",
        "Draw index"
      ]
    ],
    "note": "Uses a seeded pseudo-random generator for reproducible numbers; it is not cryptographically secure. Unique mode rejects requests when the discrete value pool is smaller than the requested count. Decimal values are rounded to the selected precision."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const rng = (s) => { let a = Math.floor(s) >>> 0; return () => { a = (a + 0x6D2B79F5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0)/4294967296; }; }; const lo = Math.min(min, max); const hi = Math.max(min, max); const size = hi - lo + 1; const d = Math.max(0, Math.min(8, Math.floor(decimals) || 0)); const f = Math.pow(10, d); const possible = d === 0 ? size : Math.floor((hi-lo)*f+1+1e-9); if (unique === 'yes' && possible < count) return {__error:'inputError',numbers:null,sum:null,average:null,range:possible,lowest:null,highest:null}; const r = rng(seed); const draw = () => { if (d === 0) return lo + Math.floor(r()*size); return Math.round((lo + r()*(size - 1))*f)/f; }; const out = []; const seen = {}; let guard = 0; while (out.length < count && guard < count*200 + 1000) { guard++; const v = draw(); if (unique === 'yes' && possible >= count) { if (seen[v]) continue; seen[v] = 1; } out.push(v); } let sum = 0, m = out[0], M = out[0]; for (const v of out) { sum += v; if (v < m) m = v; if (v > M) M = v; } return { numbers: out.join(', '), sum: sum, average: out.length ? sum/out.length : 0, range: possible, lowest: m, highest: M };",
    "inputs": [
      {
        "name": "min",
        "type": "number",
        "default": 1,
        "min": -1000000,
        "max": 1000000,
        "step": 1
      },
      {
        "name": "max",
        "type": "number",
        "default": 100,
        "min": -1000000,
        "max": 1000000,
        "step": 1
      },
      {
        "name": "count",
        "type": "number",
        "default": 5,
        "min": 1,
        "max": 200,
        "step": 1,
        "slider": true
      },
      {
        "name": "unique",
        "type": "select",
        "default": "no",
        "options": [
          {
            "value": "no"
          },
          {
            "value": "yes"
          }
        ]
      },
      {
        "name": "seed",
        "type": "number",
        "default": 12345,
        "min": 0,
        "max": 1000000,
        "step": 1
      },
      {
        "name": "decimals",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 8,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "numbers",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "sum",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "average",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "range",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "lowest",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "highest",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
