Random Text From File
Random prompts from a file you already keep on disk
- STRING
If you keep your prompt libraries as text files - and a lot of people do, because text files outlive workflows - Random Text From File is the node that plugs them into your graph. It reads a .txt or .md file from ComfyUI's input directory and hands back one entry: a specific line-pair via choice, or a random one via seed. Same family as Random Text From List, but the source of truth is a file you can edit outside ComfyUI instead of a widget.
That file-backed design is the real selling point. Prompt curation is an editing workflow - you're constantly adding, pruning, fixing typos. With an in-widget list you're editing inside the node every time. With a file, you open your editor, change a line, save, and the next run picks from the updated set. The README calls out the format support explicitly: # lines are comments (ignored), lines starting with - begin a list item, and continuation lines join the previous item. So your file can be a lightly-annotated markdown list that reads like a document and behaves like an array.
How it works
At load time it scans the input directory and builds the file_path dropdown from every .txt and .md file it finds (sorted). When you run, it reads the chosen file, parses it into blocks with the comment/list syntax above, and selects:
- fixed - return item
choice(1-based, with wrap-around) - random - seeded uniform pick across all items
There's also a file_path_override input, a wireable string that takes precedence over the dropdown. That's the "drive the filename from another node" escape hatch - handy when the file to read is itself decided dynamically.
Inputs and outputs
- file_path - dropdown of
.txt/.mdfiles in your input directory - type - fixed / random
- choice - the fixed-mode index
- seed - INT, default 0
- file_path_override - optional string, overrides the dropdown
The output is a single STRING - one entry from the file. Wire it into your prompt, positive or negative, wherever text flows.
Installing it
Standard XJNodes install. ComfyUI Manager → search "ComfyUI-XJNodes" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/alexjx/ComfyUI-XJNodes
# restart ComfyUI
No dependencies. Category: XJNodes/text.
The details that trip people up
The file location is strict: it reads from ComfyUI's input directory only (plus whatever you pass via file_path_override). Drop your prompts file in ComfyUI/input/ and it'll appear in the dropdown; if it doesn't show up, that's where to look first. The file is re-read on every execution, so edits take effect without restarting - no cache-clearing ritual. And the comment syntax is worth internalizing: # lines are skipped entirely, so you can keep a header or notes in the same file without them ever being picked as prompts. One honest caveat: random mode pulls uniformly across items, so a prompt you wrote across three continuation lines counts as one entry, same as a one-liner - balance your file accordingly. For the widget-based version with range selection, Random Text From List is the sibling; for text that isn't a list at all, you're in the wrong node.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| file_path | COMBO | 1 options: | |
| type | COMBO | 2 options: fixed, random | |
| choice | INT | 1 | — |
| seed | INT | 00–18446744073709550000 | — |
| file_path_overrideopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |