Text Random Line (NH)
Let this node roll the dice for you
- text
- picked_index
- total_lines
Text Random Line (NH) is the smallest kind of node: you paste a list of prompts, it picks one at random, and out comes a single line you wire straight into a CLIP Text Encode. That's the whole job, and it's genuinely handy once you realize how much of prompt work is just "I want a different style/location/pose every run without editing the text box each time."
You've probably seen wildcard packs do this with {style|cyberpunk|film noir} syntax. This is the same idea with none of the machinery - no wildcard file to maintain, no external dependency. Type a list, get a pick.
How it works
It splits your text on newlines, strips whitespace, and drops any empty lines, then uses Python's random module to pick one index. Two inputs, that's it:
- text - the multiline list. Default is
option A / option B / option Cso you can see it work immediately. - seed - an INT from 0 to 4294967295.
Three outputs come back: text (the picked line), picked_index (which line it chose, 0-based), and total_lines (so you know how many candidates were in the box).
The seed behaves how you'd hope: set it to anything above 0 and a given seed always picks the same line, which is what you want when you find a great result and need to reproduce it. Leave it at 0 and it's non-deterministic - a fresh roll every run. That's a deliberate design choice in the source (seed if seed > 0 else None), so don't assume 0 means "noise, but stable." It means noise.
Where it bites
The one real gotcha is ComfyUI's cache, not the node. This node has no "always re-run" flag, so if you hit Queue twice without changing the seed or the text, ComfyUI is allowed to reuse the cached result and hand you the same line twice. The fix is the same one for every random node: change the seed, or nudge any input, and it re-rolls. If you're doing a batch of variations, this is exactly why you'd drive the seed from a primitive with control_after_generate set to randomize - worth setting that once, it's a classic ComfyUI trap (the widget-control-mode setting is covered in the node-plumbing docs).
You can also ignore the text output entirely and route on picked_index - feed it into a Switch N (NH) or a List Index to vary something other than the prompt.
Install
It ships in NH-Nodes, so install the pack once: ComfyUI Manager → search NH-Nodes → install → restart, or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Restart ComfyUI after, and refresh the browser page if the node looks cached. No models, no downloads, nothing heavy - this one is pure Python.
If your list has hundreds of lines and you want to iterate through them all (one render per line) rather than one random pick, the pack's Text Split Lines (NH) node is the fancier sibling with sequential/shuffle/reverse modes. This one is for when you want a single roll of the dice.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | option A option B option C | — |
| seed | INT | 00–4294967295 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| picked_index | INT | — |
| total_lines | INT | — |