StringToolsBalancedChoiceList
Weighted picks on a list, with hand-rolled weights if you want them
- STRING
The weighted picker that takes a list - and your own weights
StringToolsRandomChoiceList picks uniformly from a list of strings. StringToolsBalancedChoiceList is the weighted sibling: same seed + text_list shape, but it can bias the pick in two ways - automatically by counting nested choice nodes, or explicitly through a weight_list input you wire in yourself. That last bit is what makes it worth knowing about even if the auto-balancing never matters to you.
How it works
Inputs: seed (INT, default 0) and text_list (a STRING list, force-input) are required; weight_list (an INT list, force-input) is optional. It's an INPUT_IS_LIST node, so text_list arrives as a whole list - typically bundled by StringToolsStringsToList or another list-of-strings producer.
The weighting logic, in order of what it prefers:
- If you supply
weight_listand its length matches the list, it uses your weights directly. That's the straightforward way to make a 3-way list pick like 50/30/20 - no graph tricks, just numbers. - Otherwise it auto-balances: if the list came from a branch that contains nested
StringToolsRandomChoice/StringToolsBalancedChoice/List nodes, it counts the leaves through that branch and splits the weight evenly across the list items - the same leaf-counting philosophy asStringToolsBalancedChoice. - Neither? Then it's uniform - effectively
StringToolsRandomChoiceList.
Either way, the pick is seeded with your seed, so same seed, same list, same weights, same result.
Like the non-list balanced node, it keeps a per-run tally of how often each element was picked, and it can print each element's weight and selection count to the console. Note that the handy Debug toggle in ComfyUI's settings is registered for StringToolsBalancedChoice proper; the List variant's debug print lives behind its own debug flag, so you'll mostly use the non-list debug toggle or trust the math. Either way, verifying your hand-rolled weights actually land where you expect is worth doing once.
The inputs that matter
- seed (INT, default 0) - change it to re-roll. A
StringToolsSeedwired in keeps the number visible. - text_list (STRING list) - the candidates. Must be a list, not individual wires.
- weight_list (INT list, optional) - your explicit weights, one per element, in the same order. Length must match
text_listor it's ignored.
Output is a single STRING - the weighted pick.
Installing it
One-pack install. ComfyUI Manager: "Install Custom Nodes", search ComfyUI String Tools (repo Taremin/comfyui-string-tools), install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/Taremin/comfyui-string-tools
Restart fully. No pip dependencies, no model files, MIT license, release 0.0.7.
Gotchas
- A
weight_listwith the wrong length is silently ignored - you fall back to auto-balancing or uniform, and there's no error to tell you. Check the Debug output if your distribution looks wrong. weight_listis INT only. If your ideal weights are 0.5/0.3/0.2, scale them to whole numbers (5/3/2) - the code normalizes viarandom.choices, which works fine on raw counts.- Lists and single strings still don't mix:
text_listwants a list port. Bundle withStringToolsStringsToListfirst. - An empty list returns an empty string. Half-disconnected upstream bundles are the usual culprit.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| seed | INT | 00–18446744073709550000 | — |
| text_list | STRING | — | |
| weight_listopt | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |