Prompt Random Choice Ex
Randomize 'Where' and 'What's There' as One Unit
- selected_text
- selected_text_safe
The plain Prompt Random Choice is flat: every line is a complete prompt fragment. That's fine until you want structure - "if the setting is a zoo, then also randomize which animal." That's what Prompt Random Choice Ex (class PromptRandomChoiceEx) adds: nested {} blocks that expand into every combination, one random pick from the full expanded list.
How it works
The author's example says it all. Feed it this:
town|zoo{animals{birds|penguins}|aquarium,{fish|jellyfish}}
and internally it expands to five leaf candidates before choosing:
town
zoo, animals, birds
zoo, animals, penguins
zoo, aquarium, fish
zoo, aquarium, jellyfish
The expansion is the key design decision: it unfolds everything into a flat leaf list first, then makes a single secrets.choice() on that list. That means every leaf has equal probability - "zoo with birds" is just as likely as plain "town". If you'd rather bias things, repeat a leaf line, same as the base node.
Two supporting details worth knowing:
- The expanded list is cached and only rebuilt when
options_textchanges. The random pick still re-rolls every run, but the (potentially expensive) expansion doesn't repeat itself. - There are hard safety caps: 64 nesting steps and 4096 expanded options, after which it raises an error rather than melting your machine on a pathological brace nest.
You can also use an empty parent with () to mean "maybe, sometimes": (){white day|wedding ceremony} expands to just the two events, no prefix - a clean way to bolt on "occasionally add a bonus element."
The inputs and outputs that matter
Identical shape to the base node:
options_text(multiline string): your list. Same|-or-newline rules, and{}blocks can nest freely - the delimiter splits only at brace depth zero, so a{...}stays intact until its children are expanded. Inner levels also split on|or newlines, and inner candidates get joined to their parent with", "(with commas cleaned up automatically).change_every(int, default 1): hold the same pick for N runs, shown in the title asEx: zoo, aquarium, fish (2/3).
Outputs:
selected_text: the chosen leaf, joined and normalized - wire into your prompt via a string-join node (kjnodes'Join String Multiis what the README recommends).selected_text_safe: filename-safe version,emptywhen the pick came out blank.
When to reach for Ex - and when not to
The author is refreshingly explicit here: Ex is not for smashing every variation into one mega-node. If you have independent slots - background, weather, time of day - use separate plain choice nodes; they're easier to read and to weight. Ex earns its keep when you have a genuine parent/child relationship: "zoo, and then which animal," "shrine, and then which kind of shrine." Parent group first, children inside the braces.
One honest difference from ComfyUI's built-in {a|b|c} syntax: it uses the same | delimiter, so you can port fragments between the two. But here the whole thing is resolved upstream as plain strings - nothing braces-y ever reaches the text encoder, and only the winning leaf flows downstream.
Installing it
Same pack, same easy install - zero dependencies, no models:
- ComfyUI Manager: search
ComfyUI-PromptRandomChoice. - Manual:
cd ComfyUI/custom_nodes git clone https://github.com/ruminar/ComfyUI-PromptRandomChoice
Restart ComfyUI after either. GPL-3.0 licensed.
Common issues
- A literal
{or}in your prompt text: not supported - braces are always expansion markers here. For literal braces, use the plain Prompt Random Choice node, which leaves them alone. - "Expanded too many options" error: you hit the 4096-leaf cap or the 64-step nesting limit. This is the safety valve working as designed; simplify the tree.
- Weighting surprises: expansion happens before the pick, so a parent with 10 children gets 10 leaves against a single-line option's one. If plain "town" feels rarer than it should, that's why - add repeats to rebalance.
- Title not updating: bundled browser extension again; restart ComfyUI and hard-refresh.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| options_text | STRING | town zoo{animals{birds|penguins}|aquarium,{fish|jellyfish}} coffee shop{cake|coffee cup} amusement park{ferris wheel|carousel|balloons} (){ white day wedding ceremony birthday party } | — |
| change_every | INT | 11–999999 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| selected_text | STRING | — |
| selected_text_safe | STRING | — |