Nodes/ComfyUI Sokes Nodes 🦬/Random Line 🦬
ComfyUI Node

Random Line 🦬

The seeded line picker that makes your prompt A/B tests reproducible

By m-sokes·Created 3 years ago·Updated 4 days ago· 4
Random Line 🦬
    • line
    • count
    â—„textline one line two line threeâ–º
    â—„seed1â–º

    ComfyUI's sampler is deterministic: same seed, same image, every time. That's the whole trick behind seed farming - lock the seed, change one thing, compare. But the rest of your graph isn't deterministic by default, and that's where Random Line earns its spot. It's a text picker that uses the seed as its source of randomness, so the choice is reproducible even while your prompts get varied.

    You paste a list into the text field - style descriptors, camera angles, subjects, negative-prompt strategies, filenames - and the node hands back exactly one line, chosen by the seed. Change the seed, get the next line. Same seed tomorrow, same line. It's the same mental model as the KSampler seed, applied to text instead of noise.

    How it works

    The mechanism is refreshingly small. The node splits the input on line breaks, strips whitespace off each line, and throws away empty ones. Then it does index = (seed - 1) % number_of_lines and returns that line. That modulo is the whole show: it's why seed 1 gives you the first line, why it wraps around when the seed runs past the end of your list, and why it's fully deterministic - there's no hidden RNG anywhere.

    Worth knowing: seed 0 wraps around to the last line, because (0 - 1) % n is n - 1. It's a one-off off-by-one surprise, not a bug, but it bites people who habitually leave seeds at 0 and wonder why they keep getting the tail of their list.

    The inputs and outputs that matter

    There are exactly two inputs, and honestly both are self-explanatory:

    • text - the multiline list. Each non-empty line is a candidate. A trailing newline won't add a phantom blank entry; empty lines are filtered before indexing.
    • seed - an integer from 0 to 2^64-1. This is your picker. Randomize or increment it elsewhere and you cycle through the list.

    The outputs:

    • line (STRING) - the picked line. Wire this into a CLIPTextEncode, a filename, a Save Image prefix, wherever text goes. That's your main hook.
    • count (INT) - how many non-empty lines were in the field. Useful when you're building loops and need to know the modulo without doing it by hand.

    One implementation detail that quietly matters: the node implements IS_CHANGED by hashing both text and seed. That means ComfyUI actually re-executes downstream when you bump the seed or edit the list - with many text nodes you have to force a rerun yourself; here you don't.

    Installing it

    Same drill as the rest of the Sokes pack. Easiest is ComfyUI Manager: open it, go to Custom Nodes Manager, search "ComfyUI Sokes Nodes", hit Install, restart.

    Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/m-sokes/ComfyUI-Sokes-Nodes.git
    cd ComfyUI-Sokes-Nodes
    pip install -r requirements.txt
    

    Then restart ComfyUI. The pack's requirements (webcolors, Pillow, opencv-python, requests) exist for its other nodes - Random Line itself uses only the Python standard library, so it'll work even if you skip the install, but just run it; it's quick.

    Where people get burned

    • It's deterministic on purpose. If you wanted a fresh random line every run, this isn't it. Feed the seed input from a randomizer (the same pack has a Random Number node; anything that produces a fresh seed works) or you'll get the same line on every fresh queue.
    • Empty text returns "" and a count of 0, with a console warning. A downstream CLIPTextEncode getting an empty string usually just produces mush, not an error - so check the preview rather than assuming.
    • It's a picker, not a wildcard system. If you want several lines picked at once or syntax like {a|b} inside a prompt, this isn't the node - that's what the wildcard/extension ecosystem is for. Random Line does one thing: one seeded pick, deterministic, reproducible.

    For the classic "same seed, change one thing" workflow this is the rare utility that makes that discipline easier rather than fighting it.

    CategorySokes 🦬

    Inputs (2)

    NameTypeDefaultDescription
    textSTRINGline one line two line three—
    seedINT10–18446744073709550000—

    Outputs (2)

    NameTypeDescription
    lineSTRING—
    countINT—