Nodes/Comfyui_PDuse/PD: Random Prompt
ComfyUI Node

PD: Random Prompt

Spinning up prompt variations without a second thought

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD: Random Prompt
    • STRING
    max_count9
    mutable_promptSwing Slide Climbing frame Sandbox See-saw Merry-go-round Jungle gym Trampoline Monkey bars Rocking horse Playhouse Hopscotch Balance beam Spring rider Water play area Ball pit Tunnel Zip line Basketball hoop Bicycle rack Spinner Climbing wall Rope ladder Tetherball Flying fox Swinging bridge Spiral slide Water sprinkler Pedal go-kart Miniature golf course
    immutable_promptsticker, Cartoon, ``
    random_sample
    seed0

    Say you're generating a sticker pack and want a dozen playground items in the same art style - swing, slide, sandbox, merry-go-round. You could hand-type forty prompts, or you could let this node build the combinations and feed them straight into a batch. That's PD: Random Prompt: a list of things, a fixed template, and it cross-products them into ready-to-encode prompts, with an option to shuffle or just take the first N.

    The default template ships with the exact use case baked in: the mutable list is a pile of playground equipment, and the immutable prompt is sticker, Cartoon, `` - the backtick placeholder is where each item gets dropped in. It's a template engine with one placeholder, and that's most of what you need for batch variation.

    How it works

    It reads mutable_prompt line by line (one item per line, blank lines stripped) and treats immutable_prompt as a template. Any line containing `` gets the placeholder replaced with each mutable item; a template without the placeholder gets , `` appended so the item lands at the end. Every mutable item × every template line becomes one prompt. Then:

    • random_sample = enable shuffles with random.sample; disable takes them in order.
    • max_count caps the output (default 9, up to 1000).
    • If you set seed to anything nonzero, it seeds Python's random so the same run is reproducible. Seed 0 means "don't bother" - you'll get a different shuffle every run.

    The output is a list of strings (the node declares OUTPUT_IS_LIST), so it's meant to be fed into something list-aware downstream - a batch image saver, a queue, or a node that iterates prompts. A progress bar shows up during generation, which is a nice touch from the pack.

    The inputs that matter

    • mutable_prompt - your variable items, one per line. The default playground list is a decent demo; you'll replace it.
    • immutable_prompt - the fixed template; use `` as the item placeholder.
    • random_sample - enable / disable.
    • max_count (1–1000) - cap on how many prompts come out.
    • seed (optional) - lock it for reproducibility.

    Installing it

    Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse.git
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Restart. No models to download - the pack's deps are numpy, Pillow, scipy, opencv-python, torchvision. Chinese-first docs (Feishu/Bilibili).

    Where people get burned

    The biggest gotcha: the output is a list, and a regular CLIP Text Encode node doesn't take lists. You need a list-aware encoder or a batch/queue system downstream, or you'll get a type error and a confused afternoon. Second, shuffling happens once per run over the built combinations, not per line - two runs with the same seed give the same prompts, but "same seed, different run" only holds if you actually set one. Third, max_count caps but doesn't pad: if you ask for 9 and only built 4 combos, you get 4. If you want every combination, set random_sample = disable and max_count high.

    CategoryPDuse/Text

    Inputs (5)

    NameTypeDefaultDescription
    max_countINT91–1000
    mutable_promptSTRINGSwing Slide Climbing frame Sandbox See-saw Merry-go-round Jungle gym Trampoline Monkey bars Rocking horse Playhouse Hopscotch Balance beam Spring rider Water play area Ball pit Tunnel Zip line Basketball hoop Bicycle rack Spinner Climbing wall Rope ladder Tetherball Flying fox Swinging bridge Spiral slide Water sprinkler Pedal go-kart Miniature golf course
    immutable_promptSTRINGsticker, Cartoon, ``
    random_sampleCOMBO2 options: enable, disable
    seedoptINT00–18446744073709550000

    Outputs (1)

    NameTypeDescription
    STRINGSTRING