Nodes/😸 YFG Comical Nodes/🐯 YFG Random Prompt From File
ComfyUI Node

🐯 YFG Random Prompt From File

Random prompts from a .txt, with your negative strings intact

By gonzaluΒ·Created 2 years agoΒ·Updated 8 days agoΒ· 29
🐯 YFG Random Prompt From File
    • positive
    • negative
    • name
    • index_current
    • index_previous
    • total_count
    • file_path
    • file_name
    • range_start
    • range_end
    β—„prompt_fileβ€”β–Ί
    β—„selection_moderandomβ–Ί
    β—„index0β–Ί
    β—„range_start0β–Ί
    β—„range_end0β–Ί
    β—„last_n_onlyfalseβ–Ί
    β—„last_n_count100β–Ί
    β—„random_sourceautoβ–Ί
    β—„ensure_uniquetrueβ–Ί
    β—„history_size100β–Ί
    β—„time_window_sec0β–Ί
    β—„retry_limit20β–Ί
    β—„use_shuffle_bagtrueβ–Ί

    Wildcard nodes are the usual answer to "I want variety," but they're also a whole ecosystem to learn. If you already keep prompts in a plain .txt file - a queue of A/B tests, a batch of concepts, a changelog of things you've tried - YFG Random Prompt From File is a much smaller hammer. Point it at the file and every run it hands you a positive prompt, its negative, and a name straight out of the sockets. No wildcard syntax, no extra swap node, no CLIP-encode rig to build.

    The file format

    Plain text, entries separated by a line of hyphens (any number works):

    positive: a cozy cabin in the snow
    negative: blurry, watermark, lowres
    name: Cabin Test A
    ----
    positive: neon city at night
    negative:
    ----
    

    positive: is required. negative: may be empty - you just leave the line blank after the colon. name: is optional and defaults to the filename. Files must be UTF-8.

    How it works

    The node parses the file once and caches the entries, keyed by file modification time - repeat runs don't re-read anything until the file actually changes on disk. Then it picks. In random mode it draws from range_start..range_end, which auto-fill to 0..totalβˆ’1 the moment you browse a file. In by_index mode it uses the INDEX widget directly, and INDEX auto-syncs to whatever was picked last run, so pinning a specific prompt is just a dropdown flip away - no typing.

    Two features matter for batch work. ensure_unique stops the node from repeating a pick within a session (within history_size and time_window_sec bounds), and the shuffle bag cycles through the whole pool before reshuffling - even coverage instead of clumps. There's also last_n_only + last_n_count, which restrict the pool to the newest N entries - handy when you keep appending prompts to the bottom of the file and want only the fresh ones.

    The random.org part

    By default (random_source: auto) the node calls random.org's true-random API if you've configured a key, and silently falls back to a local PRNG otherwise. Setting up random.org means an account, an API key in random_org_api_key.json next to the node (or the RANDOM_ORG_API_KEY environment variable), and living with their API quotas. My take: skip it. The local PRNG is perfectly fine for prompt variety, and you shouldn't create an account for this - the true-random option is a nice-to-have for people already paying for a random.org key, not a reason to get one.

    Outputs

    • positive / negative - wire both into your CLIPTextEncode.
    • name - the name: field, or the filename stem.
    • index_current / index_previous / total_count - the pick, the previous pick, and how many prompts the file has. Feed index_current into a YFG Display Value if you want to know which prompt produced which image.
    • file_path / file_name - for logging or downstream nodes.

    There are also πŸ“„ Browse and πŸ• Recent buttons on the node for picking files server-side, and your recent files are remembered in yfg_file_history.json.

    Where people get burned

    If a block doesn't parse, it's silently skipped with a note in the console - so a typo'd positive: line means one fewer prompt in the pool and you might not notice for a while. Move or delete the file and the node returns nothing; re-browse to point it at the new path. And the UTF-8 requirement is real: a file saved as Windows-1252 with curly quotes or accented characters can fail to parse blocks that look fine in a text editor.

    Installing it

    Same story as every node in the YFG Comical pack - install once, it's all there:

    cd ComfyUI/custom_nodes
    git clone https://github.com/gonzalu/ComfyUI_YFG_Comical
    

    or search YFG Comical in ComfyUI Manager, then restart. Dependencies install automatically; no model downloads. Look for it under 🐯 YFG/πŸ“ Prompts, and check the pack's example workflows if you want a ready-made wiring.

    Category🐯 YFG/πŸ“ Prompts

    Inputs (13)

    NameTypeDefaultDescription
    prompt_fileSTRINGFull path to a .txt prompt file.
    selection_modeCOMBOrandomrandom picks from range_start..range_end. by_index uses INDEX directly.
    indexINT00–18446744073709550000Used by by_index mode. Auto-syncs after every run.
    range_startINT00–18446744073709550000First prompt index to include in random pool (auto-fills to 0 when file selected).
    range_endINT00–18446744073709550000Last prompt index to include in random pool (auto-fills to total-1 when file selected). 0 = last prompt.
    last_n_onlyBOOLEANfalseWhen ON, restricts the random pool to the last N entries only (newest prompts).
    last_n_countINT1001–18446744073709550000How many entries from the end of the file to pick from (only active when last_n_only is ON).
    random_sourceCOMBOautoauto uses random.org if API key exists; else local PRNG.
    ensure_uniqueBOOLEANtrueAvoid repeating prompts within history_size / time_window_sec.
    history_sizeINT1001–100000How many recent indices to track for uniqueness.
    time_window_secINT00–86400If >0, forget uniqueness entries older than this many seconds.
    retry_limitINT201–1000β€”
    use_shuffle_bagBOOLEANtrueCycle through all prompts before repeating, then reshuffle.

    Outputs (10)

    NameTypeDescription
    positiveSTRINGPositive prompt text.
    negativeSTRINGNegative prompt text (empty if not in file).
    nameSTRINGPrompt name β€” from 'name:' field or filename if omitted.
    index_currentINT0-based index of the selected prompt. Auto-syncs to INDEX widget.
    index_previousINTIndex of the previously selected prompt this session.
    total_countINTTotal number of valid prompts found in the file.
    file_pathSTRINGFull path to the prompt file.
    file_nameSTRINGFilename of the prompt file (basename only).
    range_startINTEffective range_start used for this run.
    range_endINTEffective range_end used for this run.