Nodes/braintacles-nodes/Random Find and Replace
ComfyUI Node

Random Find and Replace

Roll a random word into your prompt, one choice per line

By braintacles·Created 3 years ago·Updated 2 years ago· 2
Random Find and Replace
    • prompt
    • random_choice
    • seed
    prompt
    findString to Find & Replace
    choicesChoices
    seed0

    If you've ever used A1111's {red|blue|green} wildcard syntax or a dynamic-prompt setup, you know the trick: drop a placeholder in your prompt and let the machine roll a value for it each run. Random Find and Replace is that idea in one dead-simple ComfyUI node - a find-and-replace where the replacement is chosen randomly from a list.

    How it works

    You give it a prompt, a find string, and a choices list with one option per line. It seeds Python's random with your seed, picks one line, and does a plain string replace - every occurrence of find in the prompt gets swapped for that choice. That last detail matters: if find appears twice, both get the same choice in one run. To get independent rolls for two placeholders, run two of these nodes with different find strings (and consider different seeds).

    Inputs: prompt (multiline), find (the placeholder text, default "String to Find & Replace"), choices (multiline, one option per line), and seed.

    Outputs: prompt (the rewritten prompt - wire this into a CLIP Text Encode), random_choice (what got picked, useful for recording it in metadata or a filename), and seed (echoed back so you can chain or log it).

    The inputs that matter

    Honestly, just two. find and choices. Everything else is the obvious default. The one structural rule is the newline: choices are split on \n, so one option per line - and watch for trailing blank lines, because an empty line is a valid choice and will happily wipe your placeholder into nothing.

    What it's for

    Prompt generator setups, per the author's own README. Batch a bunch of seeds and get variety - roll a subject, a lighting word, a style tag. Combined with the seed output, your runs stay reproducible: same seed, same choice, same image. It's a small hammer, but it's exactly the hammer for "I want a different something every run without touching the prompt by hand."

    Install

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

    or search braintacles-nodes in ComfyUI Manager and restart. No Python dependencies, no model downloads - plain string handling, so nothing about ComfyUI updates can break it. One caveat: the pack is dormant since mid-2024, but this node is as stable as string manipulation gets.

    Want more power than this? The ecosystem has bigger dynamic-prompt tools (wildcard packs with weighted options and nesting). This one is the 200-line version that does one job well and never nags you.

    Categorybraintacles/Prompt

    Inputs (4)

    NameTypeDefaultDescription
    promptSTRING
    findSTRINGString to Find & Replace
    choicesSTRINGChoices
    seedINT00–18446744073709550000

    Outputs (3)

    NameTypeDescription
    promptSTRING
    random_choiceSTRING
    seedINT