Nodes/comfyui_imgtools/Random Line Concatenator (rholdorf)
ComfyUI Node

Random Line Concatenator (rholdorf)

Seed-controlled random prompt fragments, with per-option toggles

By rholdorf·Created 8 months ago·Updated 2 days ago· 0
Random Line Concatenator (rholdorf)
    • text
    seed0
    adjust_whitespacetrue
    start
    random_choice[]
    end
    text_in

    Prompt variation is one of those things that's trivial to do badly (seed-bump the whole prompt) and annoying to do well. This node lets you build a pool of prompt fragments, toggle them on and off, and pick one at random - with a proper seed so a given run is reproducible. Wire the output into a CLIP Text Encode and you get controlled variety instead of whole-prompt roulette.

    How it works

    You maintain the random_choice pool through a custom row-based widget in the node UI: each row is a checkbox, a text field, and a delete button. Disabled rows and blank rows are skipped when picking; an empty pool returns an empty string rather than erroring - a deliberate choice, so a cleared pool doesn't kill the workflow. The pick uses random.Random(seed), so the same seed, pool, and order gives the same line every time. That's the property that makes it useful in batch generation: lock the seed, keep the variety.

    The rest is concatenation. text_in (an optional upstream string) goes first, then start, then the chosen line, then end. With adjust_whitespace on (the default), whitespace runs are collapsed and parts join with a single space, so you don't get double spaces at the seams.

    Inputs and outputs

    • seed - with the standard control-after-generate dropdown (fixed, increment, randomize).
    • adjust_whitespace, start, end - the join behavior and surround text.
    • random_choice - the pool, edited through the row widget.
    • text_in - optional input-only string, prepended before everything else.

    Output: a single text STRING. There's also a legacy fallback: if random_choice contains plain newline-separated lines instead of the JSON the UI writes, it's parsed as all-enabled entries - so saved old workflows keep working.

    Where it fits

    Batch prompts where one slot varies - style words, camera angles, subjects - while the rest stays fixed. It's a small, single-purpose node; if you need weighted randomness or full wildcard templates, you want a heavier system like a wildcard loader. For "pick one of these four things, reproducibly," this is clean and does exactly that.

    Install

    Part of the small comfyui_imgtools pack by rholdorf. Install once, get all 11 nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/rholdorf/comfyui_imgtools
    

    Restart ComfyUI. Or search "rholdorf" in ComfyUI Manager. No build step, no extra dependencies - it's pure Python plus a small JS widget. Young, low-star solo pack: MIT, short readable code, no network calls, no model downloads. The options editor lives in web/, so a browser refresh picks up JS changes; Python changes need a restart.

    Categoryrholdorf/text

    Inputs (6)

    NameTypeDefaultDescription
    seedINT00–18446744073709550000Seed for picking a line from random_choice.
    adjust_whitespaceBOOLEANtrueCollapse runs of whitespace and join parts with a single space.
    startSTRINGText prepended before the random line.
    random_choiceSTRING[]Options pool. Edit via the toggleable rows in the node UI.
    endSTRINGText appended after the random line.
    text_inoptSTRINGOptional upstream string; prepended before start/chosen/end.

    Outputs (1)

    NameTypeDescription
    textSTRING