gchq/CyberChef · error · OperationError

Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.

Error message

Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.

What it means

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.

Source

Thrown at src/core/operations/PseudoRandomIntegerGenerator.mjs:88

        this.randomBufferOffset = PseudoRandomIntegerGenerator.BUFFER_SIZE;
    }

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     */
    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":

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Keep both Min and Max within -(2^53 - 1) and 2^53 - 1 (use the arg min/max constraints in the UI).
  2. If you need a wider range, generate in smaller buckets or use a BigInt-based generator instead.
  3. Ensure numeric args are actual numbers (or null to short-circuit), not NaN/undefined.
  4. Avoid scientific notation that resolves beyond MAX_SAFE_INTEGER.

Example fix

// before: bound beyond safe integer
run("", [1, 1e16, 1e16 + 10, "Space", "Decimal"]);

// after: bounds inside safe range
run("", [1, 0, 99, "Space", "Decimal"]);
Defensive patterns

Strategy: validation

Validate before calling

const min = Math.ceil(minInt), max = Math.floor(maxInt);
if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
  throw new Error("Min/Max must be safe integers within \u00B1(2^53 - 1)");
}

Type guard

function areSafeIntegerBounds(minInt, maxInt) {
  return Number.isSafeInteger(Math.ceil(minInt)) && Number.isSafeInteger(Math.floor(maxInt));
}

Try / catch

try {
  return prng.run(input, [n, minInt, maxInt, delim, out]);
} catch (e) {
  if (e.message.includes("between `-(2^53 - 1)`")) {
    // clamp bounds into the safe-integer range and retry
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/560146a7a1b8db9b. Report an issue: GitHub.