Nodes/JJMaden Random Nodes/Random Line From File (Wildcard)
ComfyUI Node

Random Line From File (Wildcard)

Wildcard prompts with a seed story that actually makes sense

By jjmaden·Created 27 days ago·Updated about 7 hours ago· 0
Random Line From File (Wildcard)
    • random_line
    • seed_output
    text_path
    seed0
    prompt_mode
    prompt_fixed_seed0
    lora_trigger
    prefix_text

    You know the drill: you want to rotate through a list of character descriptions, styles, or LoRA trigger phrases across generations without rebuilding the graph each time. That's what wildcard systems do, and this node does it with a plain text file and none of the wildcard syntax - no __file__-style magic to learn. It reads a .txt file, picks one random line, and hands it to you as a STRING.

    What separates it from a naive "pick a random line" node is the seed story. Three prompt_mode options:

    • Follow KSampler/Seed Field - the pick is driven by the seed input (normally wired to your KSampler's seed). Same seed, same line, forever. Fully reproducible per seed.
    • Use Dedicated Prompt Seed - line selection is driven only by prompt_fixed_seed. You can keep the image seed randomizing freely while the prompt stays locked to one specific line.
    • True Independent Random - fresh OS entropy every execution. Always different, never reproducible, no seed involvement at all.

    The mechanism underneath is the interesting bit: it uses a private random.Random() instance instead of reseeding Python's global random module. An earlier version of this node did reseed the global module, which meant every other node or script in the same ComfyUI process calling random.* could have its randomness silently disturbed - and vice versa. That's fixed; this node's randomness is fully isolated from everything else in your process.

    Inputs, the short list:

    • text_path - path to your .txt file.
    • seed - normally wired to the KSampler's seed.
    • prompt_mode - one of the three above.
    • prompt_fixed_seed - only used in dedicated mode.
    • lora_trigger - replaces the literal text [trigger] in any line, so one wildcard file stays generic across multiple LoRAs.
    • prefix_text - prepended (with a space) to the chosen line, handy for a consistent style tag.

    Outputs: random_line (the STRING to feed your text encoder) and seed_output (passes seed straight through, so you can wire the same value onward).

    The file format is deliberately forgiving: blank lines are skipped, lines starting with # are treated as comments (comment out an entry without deleting it), and whitespace is stripped. One rule matters: save it as UTF-8. A file saved as UTF-16 - Notepad's default on Windows - raises a clear error rather than being silently misread. A missing file, or one with zero usable lines, also raises an error now instead of returning a literal "Error: ..." string as your prompt, which is what it used to do. Trust me, you do not want an error message as the prompt.

    cd ComfyUI/custom_nodes
    git clone https://github.com/jjmaden/comfyui-jjmaden-random-nodes
    

    Restart ComfyUI, or install via ComfyUI Manager by searching "JJMaden Random Nodes". MIT, no extra dependencies, no model downloads - the pack is a personal collection (author jjmaden).

    Two practical notes. The parsed line list is cached by the file's modification time, so a big wildcard file isn't re-read on every execution - but hand-edit the .txt and re-queue, and IS_CHANGED picks it up even with an identical seed. And the cache means there's a tiny mental model to keep: the node "notices" file edits, so you can genuinely iterate by editing the file and re-queuing. For rotating through prompt lists with sane reproducibility, this is a small, honest node that does the job without a framework attached.

    CategoryMy_Custom_Nodes

    Inputs (6)

    NameTypeDefaultDescription
    text_pathSTRING
    seedINT00–18446744073709550000
    prompt_modeCOMBO3 options: Follow KSampler/Seed Field, Use Dedicated Prompt Seed, True Independent Random
    prompt_fixed_seedINT00–18446744073709550000
    lora_triggerSTRING
    prefix_textSTRING

    Outputs (2)

    NameTypeDescription
    random_lineSTRING
    seed_outputINT