{"record":{"id":"560146a7a1b8db9b","repo":"gchq/CyberChef","slug":"min-and-max-must-be-between-2-53-1-and-2-5","errorCode":null,"errorMessage":"Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.","messagePattern":"Min and Max must be between `-\\(2\\^53 - 1\\)` and `2\\^53 - 1`\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/PseudoRandomIntegerGenerator.mjs","lineNumber":88,"sourceCode":"        this.randomBufferOffset = PseudoRandomIntegerGenerator.BUFFER_SIZE;\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const [numInts, minInt, maxInt, delimiter, outputType] = args;\n\n        if (minInt === null || maxInt === null) return \"\";\n\n        const min = Math.ceil(minInt);\n        const max = Math.floor(maxInt);\n        const delim = Utils.charRep(delimiter || \"Space\");\n\n        if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {\n            throw new OperationError(\"Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.\");\n        }\n        if (min > max) {\n            throw new OperationError(\"Min cannot be larger than Max.\");\n        }\n        const range = max - min + 1; // inclusive range\n        if (range > PseudoRandomIntegerGenerator.MAX_RANGE) {\n            throw new OperationError(\"Range between Min and Max cannot be larger than `2^53`\");\n        }\n\n        // as large as possible while divisible by range\n        const rejectionThreshold = PseudoRandomIntegerGenerator.MAX_RANGE - (PseudoRandomIntegerGenerator.MAX_RANGE % range);\n        const output = [];\n        for (let i = 0; i < numInts; i++) {\n            const result = this._generateRandomValue(rejectionThreshold);\n            const intValue = min + (result % range);\n\n            switch (outputType) {\n                case \"Hex\":","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/PseudoRandomIntegerGenerator.mjs#L70-L106","documentation":"Pseudo-Random Integer Generator requires both bounds to be safe integers after Math.ceil(min) and Math.floor(max), i.e. within -(2^53 - 1)..(2^53 - 1). Values outside that range, NaN, Infinity, or non-numeric inputs (that don't hit the earlier null check) all fail Number.isSafeInteger. The PRNG deliberately cannot represent integers beyond the safe-integer range.","triggerScenarios":"Setting 'Min Value' or 'Max Value' beyond ±(2^53 - 1) (e.g. 1e16); passing NaN or Infinity; a non-number arg that slips past the null guard (NaN !== null). Fractional values are fine after ceil/floor as long as they land inside the safe range.","commonSituations":"Trying to generate across the full int64 range; spreadsheet/recipe values expressed in scientific notation that exceed the limit; empty arg mis-coerced to NaN rather than null.","solutions":["Keep both Min and Max within -(2^53 - 1) and 2^53 - 1 (use the arg min/max constraints in the UI).","If you need a wider range, generate in smaller buckets or use a BigInt-based generator instead.","Ensure numeric args are actual numbers (or null to short-circuit), not NaN/undefined.","Avoid scientific notation that resolves beyond MAX_SAFE_INTEGER."],"exampleFix":"// before: bound beyond safe integer\nrun(\"\", [1, 1e16, 1e16 + 10, \"Space\", \"Decimal\"]);\n\n// after: bounds inside safe range\nrun(\"\", [1, 0, 99, \"Space\", \"Decimal\"]);","handlingStrategy":"validation","validationCode":"const min = Math.ceil(minInt), max = Math.floor(maxInt);\nif (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {\n  throw new Error(\"Min/Max must be safe integers within \\u00B1(2^53 - 1)\");\n}","typeGuard":"function areSafeIntegerBounds(minInt, maxInt) {\n  return Number.isSafeInteger(Math.ceil(minInt)) && Number.isSafeInteger(Math.floor(maxInt));\n}","tryCatchPattern":"try {\n  return prng.run(input, [n, minInt, maxInt, delim, out]);\n} catch (e) {\n  if (e.message.includes(\"between `-(2^53 - 1)`\")) {\n    // clamp bounds into the safe-integer range and retry\n  }\n  throw e;\n}","preventionTips":["Keep bounds within \\u00B1(2^53 - 1).","Avoid scientific notation that exceeds MAX_SAFE_INTEGER.","Ensure numeric args are real numbers or null, never NaN/undefined."],"tags":["crypto","random","numeric","input-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}