🎲 Random Tool
A random source that actually re-rolls every run
- random
Random numbers are weirdly scarce in ComfyUI. You have control_after_generate on seed widgets, which is fine until you want to randomize something that isn't a seed - a LoRA weight, a strength, a boolean that flips a switch. The 🎲 Random Tool is the general-purpose answer: four modes, one output, and it re-rolls on every single execution, not just when you remember to randomize.
The four modes, from the mode dropdown: random_int (an integer between min_val and max_val), random_float (same range, rounded to 6 decimals), random_seed (a full 64-bit integer, 0 to 2⁶⁴−1), and random_bool (True or False). The min_val and max_val inputs only matter in the first two modes - the node hides them when they're irrelevant - and the header shows the freshly generated value so you can see what you got without tracing wires. The output socket is wildcard * and its type changes with the mode, so it can feed an INT, FLOAT, or BOOLEAN input depending on what you picked.
The one behavior that defines this node - and where it differs from the naive "random widget" you might have used before - is that it always produces a new value, because it uses the IS_CHANGED → float("NaN") trick that forces ComfyUI to treat it as permanently dirty. That's exactly what you want from a random source (a random node that caches its last answer would be a debugging nightmare). But it's also the footgun: any random node sitting upstream of heavy work invalidates the cache for everything behind it, every run. If you only want to randomize occasionally, don't leave Random Tool feeding a sampler directly - put it behind a switch or disconnect it when you want stability.
Here's a subtlety worth knowing about the ranges: min_val and max_val are declared as FLOAT even though in random_int mode you get integers. So typing min_val = 2.9 in int mode silently becomes 2 after truncation. And if you flip min/max around - min 100, max 0 - the code sorts them internally rather than erroring, so you get a valid range either way. Slightly forgiving, slightly surprising; now you know.
The interesting seed note: random_seed mode isn't "the same as a random seed widget." It's a genuinely new random integer in [0, 2⁶⁴), which is a perfectly good seed to wire into a converted seed input on a KSampler. The difference is when it rolls - every execution, versus the widget's after-generate semantics that trip people up (see the classic "my seed changed but I didn't touch it" complaint). If you've ever fought control_after_generate, this is the escape hatch: a seed source whose behavior is unambiguous.
The node is marked as an output node and always runs, so you can't use it as a pure "value holder" that only recomputes on demand - that's fine, that's the design.
Install is pack-level and boring:
cd ComfyUI/custom_nodes
git clone https://github.com/playboy-dongan/ComfyUI-Logic-nodes
or ComfyUI Manager → "ComfyUI-Logic-nodes" → restart. No models, no deps.
It's a small node with a narrow job, and it does that job exactly as advertised. If "give me a fresh random number, no surprises about when" is the requirement, this is the one to grab.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mode | COMBO | random_seed | 4 options: random_int, random_float, random_seed, random_bool |
| min_val | FLOAT | 0-1000000000000000000–1000000000000000000 | — |
| max_val | FLOAT | 100-1000000000000000000–1000000000000000000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| random | * | — |