Nodes/ComfyUI-LoadRandomText/Random Text (Shuffle-Bag)
ComfyUI Node

Random Text (Shuffle-Bag)

The shuffle-bag node for LoRA eval

By thezveroboy·Created 9 months ago·Updated 9 months ago· 1
Random Text (Shuffle-Bag)
    • text
    • text_path
    • debug
    folder
    include_subfoldersfalse
    extensions.txt,.prompt,.md
    encodingutf-8
    errorsreplace
    reset_cachefalse
    reshuffle_on_wraptrue
    debug_infofalse

    The third node in this pack is the one the author actually built the pack for. His stated use case: running datasets of prompt descriptions through a freshly trained LoRA to see how it performs on text it has never seen. For that job you don't want pure random (too many repeats, some files never come up) and you don't want a fixed seed (that's the other node). You want to burn through your whole library once, seeing every file exactly one time, then start over. That's Random Text (Shuffle-Bag): a deck of cards made out of your text files.

    It's the right tool for any "fair sampling" workflow - testing a LoRA or a new checkpoint across a big prompt library, cycling through scene lists, building a varied batch where you want to know every option got a turn.

    How it works

    The first run collects the file list, shuffles it, and remembers the deck on the node instance. Each execution after that deals the next file from the deck. When the deck is exhausted it reshuffles and deals from the top again. reshuffle_on_wrap (default on) controls that end-of-deck reshuffle; flip it off and the next cycle replays the same order instead of a fresh shuffle.

    Two things follow from this being stateful:

    • Add a file to the folder mid-run and it won't join the deck. The deck is keyed to (folder, include_subfolders, extensions) only - not to the folder's actual contents. Toggle reset_cache to rebuild and reshuffle, or restart ComfyUI.
    • The deck lives on the node instance. It persists between queue runs, which is exactly what you want for "see everything once" across a long batch, but it means loading the workflow fresh or duplicating the node gives you a new deck (and you lose your place in the old one).

    Inputs and outputs

    • folder (required) - absolute path to your prompt library.
    • reset_cache - force a rebuild and reshuffle, restart the deck.
    • reshuffle_on_wrap - whether to reshuffle when the deck empties (default true).
    • include_subfolders, extensions, encoding, errors, debug_info - shared with the rest of the pack.

    Outputs are the same three as its siblings: text (the file contents, into CLIP Text Encode), text_path (which file won), and debug - empty unless debug_info is on, but when it is, it reports deck position ("Index: 3/200"). For a long eval run that's genuinely handy.

    Install

    Same as the pack: Manager search "LoadRandomText", install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/thezveroboy/ComfyUI-LoadRandomText
    

    Restart. Pure Python standard library, no models, nothing to download.

    Common issues

    • Folder-not-found and extension-mismatch errors behave like the rest of the pack: use an absolute path, and make sure your extensions are in the comma-separated list.
    • "Why am I seeing the same file again and again?" Either the deck is small (a three-file folder will repeat almost immediately, obviously) or you added files after the deck was built and the old deck is still in memory. Toggle reset_cache.
    • "The deck reset and I lost my spot." Expected - the state lives on the node instance, not in your files. If you're mid-eval, keep the workflow loaded and leave the node alone; save-and-reload restarts the deck.

    If your job is "test my LoRA against 200 prompts, fairly," this is the one you want. Classic repeats too much, Seed makes you babysit seeds, and Shuffle-Bag just deals you the next card.

    Categoryzveroboy/random

    Inputs (8)

    NameTypeDefaultDescription
    folderSTRING
    include_subfoldersoptBOOLEANfalse
    extensionsoptSTRING.txt,.prompt,.md
    encodingoptSTRINGutf-8
    errorsoptSTRINGreplace
    reset_cacheoptBOOLEANfalse
    reshuffle_on_wrapoptBOOLEANtrue
    debug_infooptBOOLEANfalse

    Outputs (3)

    NameTypeDescription
    textSTRING
    text_pathSTRING
    debugSTRING