{
  "schemaVersion": 1,
  "slug": "dice-roller",
  "category": "gaming",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "e6fe9cf23861b48992e54e8c93730cd6ecdcf6e06f3f3ec7263ec522b926f8bb",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/dice-roller.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": "r_i = int(u_i × s) + 1 → T = Σ r_i, T_m = T + m, μ = (s + 1) ÷ 2",
    "vars": [
      [
        "n",
        "number of dice"
      ],
      [
        "s",
        "sides per die"
      ],
      [
        "m",
        "flat modifier"
      ],
      [
        "r_i",
        "individual roll"
      ],
      [
        "μ",
        "expected average per die"
      ]
    ],
    "note": "The u_i stream comes from a seeded PRNG and the loop stops after n rolls. μ is the theoretical mean of one die, independent of the actual rolls; highest and lowest are the extrema of this batch."
  },
  "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 r = rng(seed); let sum = 0, hi = 0, lo = sides + 1; const list = []; for (let i = 0; i < count; i++) { const v = Math.floor(r()*sides) + 1; list.push(v); sum += v; if (v > hi) hi = v; if (v < lo) lo = v; } return { rolls: list.join(', '), total: sum, totalWithModifier: sum + modifier, average: (sides + 1)/2, highest: hi, lowest: lo };",
    "inputs": [
      {
        "name": "count",
        "type": "number",
        "default": 2,
        "min": 1,
        "max": 100,
        "step": 1,
        "slider": true
      },
      {
        "name": "sides",
        "type": "number",
        "default": 6,
        "min": 2,
        "max": 1000,
        "step": 1,
        "slider": true
      },
      {
        "name": "modifier",
        "type": "number",
        "default": 0,
        "min": -1000,
        "max": 1000,
        "step": 1,
        "slider": true
      },
      {
        "name": "seed",
        "type": "number",
        "default": 7,
        "min": 0,
        "max": 1000000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "rolls",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "total",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "totalWithModifier",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "average",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "highest",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "lowest",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
