🎲 智绘_随机提示词提取
One text box full of candidates, one random winner per run
- 📝 提取结果
- 🔢 字数
Sometimes you don't want to build a prompt from parts - you want to pick one from a menu you already wrote. That's this node's entire job. ZH_RandomPromptExtract ("🎲 智绘_随机提示词提取") takes a big multiline text box, treats each line as a candidate prompt, and randomly pulls 🔢 提取行数 of them out as the output. Paste a list of 30 phrases, hit run, get one - repeat, get another.
It's from ComfyUI-ZhiHui, a Chinese-language utility pack that brought it in from Dapao-Toolbox. It's the simpler sibling of the pack's RandomPromptCombine (which assembles from separate category boxes); this one just mines a single block of text.
How it works
Split the 📝 多行文本 input on newlines, drop blank lines, and sample. Two sampling behaviors:
- 提取行数 = 1 - one random line.
- 提取行数 > 1 - random lines without replacement (each candidate used at most once) when there are enough; if you ask for more lines than exist, it wraps around and samples with replacement until it's full.
Picked lines come back in their original order (it sorts the chosen indices), so the output reads like a coherent excerpt, not a shuffled pile. The 🎲 随机种子 widget works the standard way: 0 means non-deterministic, any nonzero value reproduces the same picks.
Like its sibling, it declares IS_CHANGED returning NaN - the "always rerun me" hook - so it actually re-rolls on every execution instead of being served the cached result. There's the same 12-option 🧰 字符串预处理 dropdown, and the same oddball 统计字数 option that swaps the output for a character count instead of the text itself.
The inputs and outputs that matter
- 📝 多行文本 - your candidate list, one per line.
- 🔢 提取行数 - how many to pull (1–9999).
- 🎲 随机种子 - 0 for random, fixed for repeatable.
Outputs are 📝 提取结果 - a list of strings, which triggers one downstream pass per item - and 🔢 字数, the character count of what was picked.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/zhuyungen/ComfyUI-ZhiHui.git
Restart ComfyUI. No models, base deps only. ComfyUI Manager search "ComfyUI-ZhiHui" also works.
Where people get burned
The list-output behavior is the recurring trap in this pack: with 提取行数 set above 1, the downstream runs once per picked line - which is often exactly what you want for "generate N variants," and a surprise if you wanted a single string. Second, "without replacement" means a short list can exhaust: if you ask for 5 from 3 candidates, the pool cycles. And the seed semantics are easy to misread - 0 is not "seed zero," it's "roll fresh entropy," so a workflow with seed 0 won't reproduce a lucky result. Set an actual number if reproducibility matters. As with every random-prompt tool, what you get is only as good as what you put in the box - and on LLM-encoded checkpoints, make sure the candidates are written for that model's prompting style, not SDXL tag habits.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| 📝 多行文本 | STRING | 每行一个候选提示词 | |
| 🧰 字符串预处理 | COMBO | 不改变 | 12 options: 不改变, 取数字, 取字母, 转大写, 转小写, 取中文, +6 |
| 🔢 提取行数 | INT | 11–9999 | — |
| 🎲 随机种子 | INT | 00–2147483647 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 📝 提取结果 | STRING | — |
| 🔢 字数 | INT | — |