Nodes/Img Label Tools/Random Subset
ComfyUI Node

Random Subset

A seedable 'pick N from a list' for prompts and labels

By rjgoif·Created 9 months ago·Updated 2 months ago· 5
Random Subset
    • string_list
    • merged_string
    • pick_indices
    input_text
    num_to_pick1
    with_replacementfalse
    random_ordertrue
    string_delimiter\n
    seed0

    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 picks num_to_pick times, 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 with string_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.

    CategoryImage Label Tools

    Inputs (6)

    NameTypeDefaultDescription
    input_textSTRING
    num_to_pickINT1
    with_replacementBOOLEANfalse
    random_orderBOOLEANtrue
    string_delimiterSTRING\n
    seedINT00–18446744073709550000

    Outputs (3)

    NameTypeDescription
    string_listSTRING
    merged_stringSTRING
    pick_indicesINT