RandomInt
RandomInt — the seed-like node that can randomize, count up, count down, or stay fixed, all within sane bounds
- INT
If you've ever wished ComfyUI's built-in seed node had a "stay inside this range" option, this is it. RandomInt (the display name of CM_IntRandomNumber) is a self-contained integer generator with four behaviors and six range constraints, and it's the newest addition to ComfyMath. Set it to Randomize, pick Custom min/max, and it'll hand you a random integer in your chosen range every run - no giant astronomically-sized seeds, no clamping shenanigans downstream.
It's genuinely useful beyond seeds, too. Need a random batch count between 2 and 8? An incremental frame counter for a video workflow that steps every run? A value that counts down and clamps at zero? RandomInt covers all of it with one dropdown, because it bundles the seed-style behavior (control_after_generation) together with range constraints in a way the stock seed node just doesn't.
The inputs that matter
- value - INT, the current value. It's the one you'll watch; the node writes generated results back to this widget.
- constraint - six options:
Full range,1 to max Int,0 to max Int,Min int to -1,Min int to 0,Custom min/max. - min / max - INT, default −1 and 1. Only used when
Custom min/maxis selected - they're always visible, and that trips people up. SetCustom min/max, then set your real bounds. - control_after_generation -
Fixed,Increment,Decrement, orRandomize(the default).
Output is a single INT. Everything uses signed 64-bit integer fields, so the range ceiling is roughly ±9.2 quintillion.
How it works, including the sneaky bits
When control_after_generation is Fixed, the node just returns value and tells ComfyUI nothing changed - so it doesn't rerun. Any other mode returns a deliberately "always changed" signal (the NaN trick the engine uses to force a node to run every single time), then rolls or steps the value. Increment and Decrement clamp to your bounds, so a counter can't walk off the edge. Under the hood it uses random.SystemRandom, the OS-level RNG, which is about as good as it gets for non-repeating randomness. A small frontend hook in the pack writes the generated value back into the visible value widget so what you see is what you got.
The trap everyone hits once: same as the classic seed control, the "after" in control_after_generation means the widget updates after the run - the number shown is the one that will be used next, not the one that just executed. If you randomize, see a great result, and switch to Fixed to keep it, you've already lost it. The stock ComfyUI advice applies: switch "widget control mode" to Before in your settings and this whole class of pain disappears.
Second gotcha: when the node isn't Fixed, it's permanently "dirty," which defeats ComfyUI's caching for everything downstream. In a workflow where RandomInt feeds a big sampler chain, that means no caching benefits - fine for occasional runs, mildly wasteful in a batch loop. That's the documented cost of "must run every time."
Installing it
It ships in ComfyMath, published as ComfyMath-NG. Install via ComfyUI Manager - search "ComfyMath" - or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/rabanti-github/ComfyMath.git ComfyMath-NG
Restart ComfyUI. This fork registers the same node IDs as the original ComfyMath, so disable or remove the original first. Only dependency is numpy; nothing to download.
The one-line recommendation
For seeds: constraint 0 to max Int keeps you out of negative-seed weirdness, or Custom min/max for a tight band. For counters and ramps, Increment/Decrement with bounds is the cleanest loop logic you'll find in a single node.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| value | INT | 0-9223372036854776000–9223372036854776000 | — |
| constraint | COMBO | 6 options: Full range, 1 to max Int, 0 to max Int, Min int to -1, Min int to 0, Custom min/max | |
| min | INT | -1-9223372036854776000–9223372036854776000 | — |
| max | INT | 1-9223372036854776000–9223372036854776000 | — |
| control_after_generation | COMBO | Randomize | 4 options: Fixed, Increment, Decrement, Randomize |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |