gchq/CyberChef · error · OperationError
Min cannot be larger than Max.
Error message
Min cannot be larger than Max.
What it means
After confirming both bounds are safe integers, the generator checks that Min is not greater than Max. A reversed range is meaningless for the inclusive sampling loop, so it throws rather than silently producing nothing. Note the bounds are first ceil'd/floor'd, so a fractional Min/Max pair that crosses after rounding can also trip this.
Source
Thrown at src/core/operations/PseudoRandomIntegerGenerator.mjs:91
/**
* @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":
output.push(intValue.toString(16));
break;
case "Decimal":View on GitHub (pinned to 4290ea7539)
Solutions
- Set Min to a value <= Max.
- If using fractional bounds, account for ceil(Min) and floor(Max) so they do not invert.
- Swap the two arg values if they are transposed.
Example fix
// before: min > max
run("", [1, 100, 10, "Space", "Decimal"]);
// after: min <= max
run("", [1, 10, 100, "Space", "Decimal"]); Defensive patterns
Strategy: validation
Validate before calling
const min = Math.ceil(minInt), max = Math.floor(maxInt);
if (min > max) throw new Error(`Min (${min}) must be <= Max (${max})`); Type guard
function isOrderedRange(minInt, maxInt) {
return Math.ceil(minInt) <= Math.floor(maxInt);
} Try / catch
try {
return prng.run(input, [n, minInt, maxInt, delim, out]);
} catch (e) {
if (e.message === "Min cannot be larger than Max.") {
// swap bounds if transposed, then retry
}
throw e;
} Prevention
- Set Min <= Max.
- Watch fractional bounds that invert after ceil/floor.
- Double-check transposed arg order.
When it happens
Trigger: Setting 'Min Value' higher than 'Max Value' (e.g. min 100, max 10). Also possible with fractional inputs where Math.ceil(min) ends up greater than Math.floor(max) (e.g. min 5.9 -> 6, max 5.1 -> 5).
Common situations: Swapping the min/max fields by mistake; fractional bounds that invert after rounding; importing a recipe with transposed args.
Related errors
- Min and Max must be between `-(2^53 - 1)` and `2^53 - 1`.
- Range between Min and Max cannot be larger than `2^53`
- ${err.toString()}
- Error: ${err.toString()}
- Invalid Base64 payload
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/14d586dc1cf81a4e.
Report an issue: GitHub.