Random Subset
A seedable 'pick N from a list' for prompts and labels
- string_list
- merged_string
- pick_indices
Random Subset is a small utility with a clear job: take a newline-delimited list of strings and randomly pick N of them. You feed it a block of prompt variations, labels, or checkpoint names, and it returns the chosen subset in three convenient forms. It's the kind of node you don't miss until you're hand-picking three out of twelve prompts for the tenth time.
The mechanism is straightforward and worth knowing because it's seeded. It parses your multiline input_text into a list (blank lines are filtered out), then uses Python's random module seeded by the seed input. Same seed, same picks, every time - which is exactly what you want if you're comparing results across runs. Change the seed and the selection changes. It's deterministic in a way that makes workflows reproducible, which the wider ecosystem treats as gospel for anything involving randomness.
The inputs that matter
input_text- your multiline list, one item per line.num_to_pick- how many to select. Without replacement, it's capped at the list length (you can't pick more unique items than exist); with replacement, it picksnum_to_picktimes, so duplicates are possible.with_replacement- off by default. Leave it off unless you genuinely want repeated picks.random_order- on by default. When on, the picked items are shuffled, not just sampled; off, they keep their original relative order. If you're picking labels to line up with a fixed sequence of images, you probably want this off.seed- reproducibility. Lock it while iterating.string_delimiter- how the merged output joins the picks. The default is\n(literal backslash-n, which the node turns into real newlines in the merged string), so you can get a newline-joined block back if that's what your downstream node expects.
The outputs
Three, all about how you consume the pick:
string_list- the picked items as a list.merged_string- the same items joined by your delimiter into one string.pick_indices- the original indices of the picks, aligned withstring_list. This is the underrated one: if your labels sit parallel to another list (like an image batch), the indices let you subset that other list by hand with a list-slicing node.
Install
It's part of Img Label Tools: ComfyUI Manager → search "Img Label Tools" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/rjgoif/ComfyUI-Img-Label-Tools
Restart ComfyUI after either. No models, no dependencies beyond what ComfyUI ships.
Gotchas
Two small ones. The delimiter default looks like a newline but it's a literal \n string in the widget - that's intentional and the node handles it, so don't "fix" it by typing an actual newline into a single-line field. And remember random_order shuffles the picks, so if you set it and wonder why your labels no longer match your images, that's why. For label duty in this very pack (feeding Image Array's label_input), you usually want random_order off and a fixed seed.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| input_text | STRING | The items to choose from, one per line. Blank lines are ignored. | |
| num_to_pick | INT | 1 | How many items to pick. Without replacement this is capped at the number of items. |
| with_replacement | BOOLEAN | false | ON: the same item can be picked more than once, and num_to_pick is not capped. OFF: each item is picked at most once. Ignored when pick_mode is cycle. |
| random_order | BOOLEAN | true | ON: shuffle the picked items one more time before output. OFF: skip that extra shuffle and output them in the order they were drawn. This is not the original list order, except when every item is picked. |
| string_delimiter | STRING | \n | Text placed between items in merged_string. Type \n for a new line. |
| seed | INT | 0-1–18446744073709550000 | Random seed. The same seed and settings always give the same picks. In cycle mode, the seed selects the window: seed S starts at item (S * num_to_pick) mod item count. |
| pick_modeopt | COMBO | random | random: pick items at random using seed. cycle: pick a consecutive window of num_to_pick items, wrapping from the end back to the start. Seed 0 picks the first window, seed 1 the next, and so on, so incrementing the seed walks through every item in order. In cycle mode with_replacement is ignored and num_to_pick is capped at the number of items. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| string_list | STRING | The picked items as a list, one entry per item. |
| merged_string | STRING | All picked items joined into one string with string_delimiter. |
| pick_indices | INT | Position of each picked item in the input list, counting from 0 (blank lines are not counted). |