Just stumbled on something simple that might save someone a community node install: you can turn the native Switch node into a random router without any code.
How:
- Add a Switch node, set Mode to
Expression - Set Number of Outputs to however many branches you want (N)
- Set Output Index to:
{{ Math.floor(Math.random() * N) }}
(replace N with your actual number of outputs)
That’s it — each execution randomly lands on one of the N outputs. Math.random() returns 0–1, so Math.floor(x * N) maps cleanly onto index 0 to N-1.
Figured I’d share since I’ve seen a few community nodes built specifically to solve this (random/percentage routing), but the built-in Switch node already handles the basic case out of the box.
If you try it out, let me know if it helps or if you run into any edge cases — curious to hear how others end up using it.