🎲 Weighted Multiline Randomizer
The weighted randomizer the rest of this pack is built on
- selected_text
If you install ComfyUI_TextRandomizer for one node, it's this one. Every other randomizer in the pack - the tag replacers, the file loader - is a thin wrapper around the engine sitting inside "🎲 Weighted Multiline Randomizer". What it does is simple and genuinely useful: you give it a stack of prompt lines, it picks one at random (with the odds you set), then expands every {choice|choice} block inside what it picked. Same idea as the old A1111 bracket trick that the KB's prompt-engineering notes keeps resurfacing - batch 32 runs and get 32 variations of one character - except here you control the weights and the seed.
How it works
The multiline text box is your pool of candidates, one per line. Each line can carry a weight by appending ::number:
A professional photo of a {female::5|male} mage, casting a {fire::5|ice::2|lightning} spell, cinematic lighting.
golden hour portrait, 85mm, film grain :: 3
street shot, harsh flash, candid :: 2
::5 means that line gets picked five times as often as a line with no weight. Weights work the same way inside the curly braces: {fire::5|ice::2|lightning} makes fire five times likelier than lightning, ice twice as likely. Once a line is chosen, the node walks the braces and expands them - up to ten passes, so you can nest to a reasonable depth - then hands the finished string back.
That seed input matters more than it looks. The node calls random.seed(seed) before drawing, so the same seed plus the same text box produces the same pick, every time. This is the "lock the seed, change one thing" debugging discipline from the troubleshooting knowledge base, applied to prompts instead of pixels. When you land a run you love, note the seed and you can reproduce that exact prompt forever.
The inputs that matter
- text - your candidate lines. One line per option;
::weighton the end sets the odds. - seed - locks the pick. Feed it from a seed node (or
control_after_generateon the widget) to roll a fresh prompt each run. - regex_pattern / regex_replacement (optional) - a cleanup pass that runs after selection. The default is
,\s*,→,, which swallows the stray ", ," that empty bracket picks can leave behind. Clear the pattern field and cleanup stops.
Output: selected_text (STRING). Wire it into a CLIP Text Encode, or into a concatenator if you're gluing it onto a fixed base prompt.
Installing it
Same story as the rest of the pack - the author's README is literally "TODO.", but this one installs clean because there's nothing to install. No requirements.txt, no model downloads, no VRAM, pure Python stdlib.
ComfyUI Manager → Custom Nodes Manager → search "TextRandomizer" → Install → Restart
or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/fls-eugene/ComfyUI_TextRandomizer
then restart ComfyUI. That's the whole install.
Gotchas
The {a::5|b} syntax is this pack's flavor of the bracket trick - the plain {a|b} form also works, so old A1111 muscle memory transfers. If a replacement comes out with stray commas, your regex cleanup is the culprit - either it's disabled (empty pattern) or your bracket content legitimately ends with a comma. And if a run doesn't look random, check whether the seed is actually changing between runs; a fixed seed is doing exactly what you told it to.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | A professional photo of a {female::5|male} mage, casting a {fire::5|ice::2|lightning} spell, cinematic lighting. | — |
| seed | INT | 00–18446744073709550000 | — |
| regex_patternopt | STRING | ,\s*, | — |
| regex_replacementopt | STRING | , | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| selected_text | STRING | — |