π― YFG Random Prompt From File
Random prompts from a .txt, with your negative strings intact
- positive
- negative
- name
- index_current
- index_previous
- total_count
- file_path
- file_name
- range_start
- range_end
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_currentinto 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.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt_file | STRING | Full path to a .txt prompt file. | |
| selection_mode | COMBO | random | random picks from range_start..range_end. by_index uses INDEX directly. |
| index | INT | 00β18446744073709550000 | Used by by_index mode. Auto-syncs after every run. |
| range_start | INT | 00β18446744073709550000 | First prompt index to include in random pool (auto-fills to 0 when file selected). |
| range_end | INT | 00β18446744073709550000 | Last prompt index to include in random pool (auto-fills to total-1 when file selected). 0 = last prompt. |
| last_n_only | BOOLEAN | false | When ON, restricts the random pool to the last N entries only (newest prompts). |
| last_n_count | INT | 1001β18446744073709550000 | How many entries from the end of the file to pick from (only active when last_n_only is ON). |
| random_source | COMBO | auto | auto uses random.org if API key exists; else local PRNG. |
| ensure_unique | BOOLEAN | true | Avoid repeating prompts within history_size / time_window_sec. |
| history_size | INT | 1001β100000 | How many recent indices to track for uniqueness. |
| time_window_sec | INT | 00β86400 | If >0, forget uniqueness entries older than this many seconds. |
| retry_limit | INT | 201β1000 | β |
| use_shuffle_bag | BOOLEAN | true | Cycle through all prompts before repeating, then reshuffle. |
Outputs (10)
| Name | Type | Description |
|---|---|---|
| positive | STRING | Positive prompt text. |
| negative | STRING | Negative prompt text (empty if not in file). |
| name | STRING | Prompt name β from 'name:' field or filename if omitted. |
| index_current | INT | 0-based index of the selected prompt. Auto-syncs to INDEX widget. |
| index_previous | INT | Index of the previously selected prompt this session. |
| total_count | INT | Total number of valid prompts found in the file. |
| file_path | STRING | Full path to the prompt file. |
| file_name | STRING | Filename of the prompt file (basename only). |
| range_start | INT | Effective range_start used for this run. |
| range_end | INT | Effective range_end used for this run. |