gchq/CyberChef · error · OperationError
Range between Min and Max cannot be larger than `2^53`
Error message
Range between Min and Max cannot be larger than `2^53`
What it means
Even when both bounds are safe integers and Min <= Max, the inclusive range (Max - Min + 1) must not exceed Number.MAX_SAFE_INTEGER (2^53 - 1). The rejection-sampling logic and 53-bit random stitching cannot represent a larger range, so the op refuses. This trips when the two safe-integer bounds sit near opposite ends of the safe-integer spectrum.
Source
Thrown at src/core/operations/PseudoRandomIntegerGenerator.mjs:95
*/
run(input, args) {
const [numInts, minInt, maxInt, delimiter, outputType] = args;
if (minInt === null || maxInt === null) return "";
const min = Math.ceil(minInt);
const max = Math.floor(maxInt);
const delim = Utils.charRep(delimiter || "Space");
if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
throw new OperationError("Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.");
}
if (min > max) {
throw new OperationError("Min cannot be larger than Max.");
}
const range = max - min + 1; // inclusive range
if (range > PseudoRandomIntegerGenerator.MAX_RANGE) {
throw new OperationError("Range between Min and Max cannot be larger than `2^53`");
}
// as large as possible while divisible by range
const rejectionThreshold = PseudoRandomIntegerGenerator.MAX_RANGE - (PseudoRandomIntegerGenerator.MAX_RANGE % range);
const output = [];
for (let i = 0; i < numInts; i++) {
const result = this._generateRandomValue(rejectionThreshold);
const intValue = min + (result % range);
switch (outputType) {
case "Hex":
output.push(intValue.toString(16));
break;
case "Decimal":
output.push(intValue.toString(10));
break;
case "Raw":
default:View on GitHub (pinned to 4290ea7539)
Solutions
- Narrow the range so (Max - Min + 1) <= 2^53 - 1.
- If you need the full spectrum, split into multiple smaller-range calls and combine.
- Use a dedicated BigInt-capable generator for ranges beyond MAX_SAFE_INTEGER.
Example fix
// before: full safe-integer span
run("", [1, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, "Space", "Decimal"]);
// after: bounded range within limit
run("", [1, 0, 99, "Space", "Decimal"]); Defensive patterns
Strategy: validation
Validate before calling
const min = Math.ceil(minInt), max = Math.floor(maxInt);
const range = max - min + 1;
if (range > Number.MAX_SAFE_INTEGER) {
throw new Error(`Range ${range} exceeds 2^53 - 1; narrow the bounds`);
} Type guard
function rangeWithinSafeIntegerLimit(minInt, maxInt) {
return Math.floor(maxInt) - Math.ceil(minInt) + 1 <= Number.MAX_SAFE_INTEGER;
} Try / catch
try {
return prng.run(input, [n, minInt, maxInt, delim, out]);
} catch (e) {
if (e.message.includes("cannot be larger than `2^53`")) {
// narrow the range or split into multiple calls
}
throw e;
} Prevention
- Keep (Max - Min + 1) within 2^53 - 1.
- Split very wide ranges into multiple smaller calls.
- Use a BigInt-capable generator for full int64 ranges.
When it happens
Trigger: Min near -(2^53 - 1) and Max near 2^53 - 1, so Max - Min + 1 exceeds 2^53 - 1. For example min = -Number.MAX_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER.
Common situations: Trying to span the entire safe-integer spectrum; generating IDs over a very wide range without considering the implementation limit.
Related errors
- Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.
- Min cannot be larger than Max.
- ${err.toString()}
- Error: ${err.toString()}
- Invalid Base64 payload
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/c29cafc9240fffd3.
Report an issue: GitHub.