Random Switch
Randomly pick one of many inputs, reproducibly
- inputs
- *
- seed
Most "switch" nodes in ComfyUI are either a manual A/B valve (you flip a selector) or a fallback (rgthree's Any Switch hands you the first non-empty input). Random Switch is neither. It rolls a die across two to thirty-two inputs, hands you the winner, and tells you what it rolled. Same seed, same pick; seed zero, and it rolls a fresh die every run. That's the whole node.
So why would you reach for it? Variation, mostly - the "surprise me" workflows. Wire three or four LoRAs into it, let each run pick one at random, and you're doing cheap style exploration without touching a selector. Random conditioning, random latent, one of several checkpoints loaded into the graph: anything where you want the graph to choose for you, but in a way you can still pin down afterward. The seed it outputs is the whole point - you can wire it into a KSampler seed so the image's random factor and the branch choice stay locked together, and when one comes out good, you've got the exact combination that made it.
How it works
The mechanism is two lines of Python, and it's honest about it. When the run starts, if seed is 0 it generates a random integer; then it seeds a fresh random.Random(seed) and calls choice() on your inputs. Because the RNG is seeded per-run rather than reused, a fixed seed always lands on the same input - reproducibility is exact, not approximate.
The part you can't see from the canvas is IS_CHANGED, which returns float("nan"). That's the well-known always-rerun trick in the plumbing layer: a NaN is never equal to itself, so ComfyUI's cache always decides this node changed and re-executes it. Necessary here - a random node that got cached would just repeat itself forever. The cost, worth knowing, is that the NaN makes everything downstream always dirty too. In a big graph that's the difference between a fast incremental re-run and a full one, so don't bolt this onto a heavy chain you're iterating on. Keep the dice roll near the front of the graph and it's a non-issue.
It's also worth knowing what it isn't doing: it's not a first-non-null fallback, and it doesn't validate that your inputs match. All inputs must be the same type - that's on you, not it.
The inputs and outputs that matter
There are exactly two inputs.
- inputs (autogrow): 2–32 sockets of any type, all the same type. The UI adds the next socket automatically when you connect the current last one. If you don't wire at least two, there's nothing to pick from.
- seed (INT, default 0):
0means "roll a fresh seed this run." Any other value pins the selection - same seed, same input, every time. Like every integer widget it has acontrol_after_generatedropdown, so mind the classic gotcha: with it set torandomize, the number shown after a run is the one that will be used next, not the one that just ran.
Two outputs: * (the selected input value, any type, so it plugs straight into whatever consumed one of your inputs) and seed (the seed that was used - feed this back into the node, or into a KSampler, to lock the whole run).
Installing it
No model files, no requirements, no dependencies - it's pure Python standard library. ComfyUI Manager: search ComfyUI-RandomSwitch and install. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/tttamaki/ComfyUI-RandomSwitch.git
Then restart ComfyUI. That's genuinely the whole install.
The one real gotcha
This node is written against ComfyUI's newer V3 backend authoring API (io.ComfyNode, comfy_entrypoint, no NODE_CLASS_MAPPINGS anywhere). That reads as "new," not "broken" - but it means the node only loads on a ComfyUI recent enough to have that API. If you search the node list and find nothing, it's not the install, it's your ComfyUI being old. Update ComfyUI and it appears.
One honest caveat before you commit a workflow to it: it's a one-man (and, per the README, one-Copilot) pack with essentially no community footprint and a zero-impression page. For a ten-line utility node that's fine - there's little to break. But if you want random selection with a longer support tail, roll your own with a Primitive and a random-powered expression node; the logic is small either way. For now, Random Switch does exactly what the box says, and the seed output is the feature.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| inputs | COMFY_AUTOGROW_V3 | — | |
| seed | INT | 00–18446744073709550000 | Seed for random selection. If 0, a random seed is generated. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| * | * | — |
| seed | INT | — |