Smart Random Txt Loader (Tlant V4)
The 'Read Every Prompt Exactly Once' Loader (Before It Repeats Itself)
- file_content
- file_path
- read_count
- total_count
The "Smart" loader, aka Tlant V4, fixes the one thing that makes the plain random loaders annoying: plain random pickers repeat. With fifty prompts in a folder, random.choice will hand you the same one twice long before you've seen all fifty. V4 keeps a running list of which files it's already read and picks only from the unread ones - so every prompt gets its turn, and only when you've been through all of them does it reset and start over. If you're running a long batch that should tour your whole prompt library, that's the behavior you actually want.
How it works
The state lives in a process-level shared dictionary keyed by (dir_path, is_recursive), guarded by a lock so ComfyUI's parallel execution doesn't trip over itself. On each run it rescans the directory live - so files you drop in mid-run get picked up, and files you delete get pruned from the seen-set instead of piling up. Then it computes the unread set, randomly picks one from it, adds it to the seen list, and only clears the whole thing when every file has been read.
Outputs are the informative ones: besides file_content and file_path, you get read_count and total_count - i.e. "this was file 7 of 23." That's genuinely useful for progress tracking in a big batch, and it's the kind of thing the plain random loaders don't give you.
Inputs and outputs
Only two inputs: dir_path (absolute path to your prompt folder) and is_recursive (enum, default "true" here - this one assumes you have nested folders). Outputs: file_content, file_path, read_count (INT), total_count (INT).
Install
Same pack, same install:
cd ComfyUI/custom_nodes
git clone https://github.com/Tlant/ComfyUI-OllamaPromptsGeneratorTlant
restart ComfyUI, and you're set. Manager also has it as "Smart Random Txt Loader (Tlant V4)."
The catches, honestly
- The state is process-level and per-directory. It resets when you restart ComfyUI, and each directory key tracks separately - which is mostly what you want, but don't expect persistence across a reboot.
- Same error-as-output behavior. Bad path or empty folder →
[Error] ...strings come back asfile_content. Theread_count/total_countgo to0/0so you can branch on that. - It's not a fair shuffle replacement. Files are read in random order but with no-replacement, then it resets. If you actually wanted true "random with repeats" - the roulette feel - the plain V2/V3 loaders are the better tool. Use V4 when you want coverage: every prompt tested before anything repeats.
For batch prompt tours - "test every one of my 40 prompts once" - it's the right node in the family, and the read/total counters are a nice touch you won't find elsewhere.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| dir_path | STRING | — | |
| is_recursive | COMBO | true | 2 options: true, false |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| file_content | STRING | — |
| file_path | STRING | — |
| read_count | INT | — |
| total_count | INT | — |