ComfyUI Node

Random Text Picker

Random Text Picker draws a .txt from your folder

By hvnyiv·Created 3 months ago·Updated about a month ago· 0
Random Text Picker
    • text
    • file_path
    • selected_index
    folder_path
    moderandom
    seed0
    index0
    recursivefalse
    file_pattern*.txt
    encodingutf-8
    strip_whitespacetrue

    You've written 40 prompts and you want a different one every run - without hand-editing the CLIP Text Encode node between batches. That's the whole job of Random Text Picker: it looks in a folder, picks one .txt file, and outputs its contents as a STRING. Feed that into your positive prompt and ComfyUI starts rolling the dice on which prompt you get. It's the folder-based cousin of the old A1111 {brown|blonde|black} bracket trick, minus the brackets - your alternatives are separate files on disk.

    How it works

    Under the hood it's simple and predictable. The node lists every file matching file_pattern (default *.txt) in folder_path, sorts the list alphabetically, then picks one:

    • random - random.Random(seed).randrange(file_count). Note the seeded random: same seed, same pick, every single time. "Random" only changes when the seed changes.
    • sequential - index % file_count, so it walks the folder and wraps around. Great for cycling through prompts in order.
    • index - direct pick by position, and it throws an error if index is out of range.

    It also implements IS_CHANGED with a signature of each file's path, mtime, and size, so ComfyUI re-runs the node when you add, remove, or edit a file without restarting. If you've read about ComfyUI's node cache, this is the correct, tasteful version of "make the node notice changes" - no float("NaN") hack, just a real signature.

    The inputs and outputs that matter

    • folder_path - absolute or relative path to your prompt folder. This is the one you'll set first.
    • mode - random is the default and what most people want; sequential and index are there when you need deterministic rotation.
    • seed - only meaningful in random mode, but it's the thing that decides whether you get variety. Wire a seed source here (or leave the widget on randomize) or every run picks the same file.
    • file_pattern + recursive - for subfolders or non-.txt files.
    • encoding - utf-8 is right for almost everything, but gbk and latin-1 are there for text files that were saved as something else. If you're pulling prompts from a Chinese tag site, you've seen this one before.

    Outputs: text (wire it into a CLIP Text Encode or any STRING input), plus file_path and selected_index as breadcrumbs - useful if you want to log which prompt produced which image, since the output PNG metadata will carry the file path anyway.

    Where the burns happen

    The big one: random is seeded, so it isn't random by default. Same seed, same file, forever. If your results never change, that's not a bug - it's the seed not moving. Randomize it (a seed node, or control_after_generate set to randomize - the "widget control mode" fix from the plumbing docs applies here too) and the wheel actually spins.

    Second: the folder has to exist and contain matching files. Empty folder or wrong pattern throws No files matching '*.txt' found in: ..., and a missing folder throws a NotADirectoryError. Both are loud and readable, which is more than most text nodes manage.

    Third: strip_whitespace defaults to True, which trims the whole file. That's what you want for a one-line prompt, but if your file has intentional blank lines or formatting, flip it off - otherwise your multi-line prompt collapses into a single line.

    Installing it

    This ships as part of ComfyUI-Random-Text-Picker (the README brands it "ComfyUI Prompt Tools"). Easiest route is ComfyUI Manager: search "Random Text Picker" or "Prompt Tools", install, restart. By hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/hvnyiv/ComfyUI-Random-Text-Picker
    

    Then restart ComfyUI. No requirements.txt, no model downloads - it only uses ComfyUI's own internals and the Python standard library. One quirk: the README's own clone command uses an older repo name (ComfyUI-Prompt-Tools.git). It still resolves because GitHub redirects renamed repos, but it creates a differently-named folder than Manager installs, so stick with the current URL. Update with git pull and a restart, and hit Ctrl+F5 if the browser is still showing an old UI.

    Categorytext/random

    Inputs (8)

    NameTypeDefaultDescription
    folder_pathSTRING
    modeCOMBOrandom3 options: random, sequential, index
    seedINT00–18446744073709550000
    indexINT00–999999
    recursiveBOOLEANfalse
    file_patternSTRING*.txt
    encodingCOMBOutf-84 options: utf-8, utf-8-sig, gbk, latin-1
    strip_whitespaceBOOLEANtrue

    Outputs (3)

    NameTypeDescription
    textSTRING
    file_pathSTRING
    selected_indexINT