Elegant Random Number
Random That You Can Still Reproduce
- int
- float
- string
Sooner or later you want a number to be random. Which of five prompts gets used this run. A step count jittering between 18 and 24. A die roll deciding whether a branch runs at all. ComfyUI's answer is "convert a widget to an input and hook up a primitive" - which gives you a fixed value. So people fake randomness with a spare seed widget and a math expression, or skip it.
Elegant Random Number is the node for that gap: one number, drawn from a seed, with the same seed-control machinery every sampler already has.
Why the seed matters
Random-but-reproducible is the point, and it's what homemade solutions get wrong. random.random() in a custom node gives a different value on every queue with no way back to the one that made the image you liked. This draws from the seed, so seed 42 over 1–100 gives the same number today and next month.
The second reason is plumbing: one source, many consumers. Fan the number out to five widgets instead of typing it into five places and forgetting one - the whole point of the layer comfyui-node-plumbing.md describes.
How it works
Underneath it's boring, in the good way - Python's random module, seeded with your seed. Integer draws cover every whole number between min and max, both ends included. Float draws give a decimal in the range. min and max are sorted internally, so a negative range, or swapping them, is fine.
The node produces all three outputs at once - int, float, string - typed differently, so pick the socket that matches what you're feeding:
intinto anything whole-numbered: a step count, or theindexof this pack's Multi Preview in switch mode (a random pick from a list of prompts, say).floatwhen you actually want the decimals. Theintoutput of a float draw just cuts them off -3.7becomes3, not4.stringfor prompt text, filenames, notes.
The preview shows the value, the range and the seed.
Inputs you actually set
seed is ComfyUI's standard seed, with the same control after generate dropdown (fixed, increment, decrement, randomize) that KSampler has. That dropdown is where the one reliable trap lives: it fires after the run by default, so with randomize the seed in the box is the seed for the next run, not the one that produced what you're looking at. Set Settings → Lite Graph → Node Widget → Widget control mode → before once, and the number you see is the number that was used. The pack also gives you three rescue buttons: 🎲 Random, 🎲 Random → fixed, and ♻️ Last seed → fixed, which puts back the seed of the last finished run and locks it. Queued runs don't count.
min and max are floats, defaults 1 and 100, both ends included.
number_type is an int / float toggle, int by default. It picks both the draw and the printed shape of the value.
Installing it
ComfyUI Manager, search Elegant Nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/wipeer/comfyui-elegant-nodes.git
pip install -r comfyui-elegant-nodes/requirements.txt
Restart and refresh. The pack's only Python dependency is simpleeval, which ComfyUI already installs, so there's nothing to fight with. It needs ComfyUI 0.4.0 or newer (V3 node API), and the node lives under utilities/elegant.
Things that will bite you
The number never changes. Check control after generate. On fixed, the same seed means the same number forever - correct behaviour, and the reason fixed is useful once you've found a value you like.
You upgraded from 1.3.0 and the node looks wrong. Old versions had their own random/fixed mode switch; from 1.4.0 it uses ComfyUI's standard seed control, and widget values from workflows saved back then land in the wrong fields. Delete the node and add a fresh one.
An int draw over a fractional range errors. min 1.2, max 1.8 with int selected contains no whole number, and the node says so instead of guessing.
Seeds above 2⁵³ − 1 can't be generated by the buttons. That's the largest integer a browser represents exactly, and ComfyUI's own randomize has the same ceiling. You can still type a bigger one.
In a subgraph, seed is promoted automatically and the buttons appear on the subgraph node, with the value showing there after each run. control after generate stays on the inner node - ComfyUI doesn't promote it - so changing it by hand means opening the subgraph. Most of the time the buttons save you the trip.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| seed | INT | 00–18446744073709550000 | The seed the number is drawn from. Same seed, same number. |
| min | FLOAT | 1-1000000000000–1000000000000 | Smallest possible number. |
| max | FLOAT | 100-1000000000000–1000000000000 | Largest possible number. |
| number_type | BOOLEAN | true | int: a whole number (min and max included). float: a decimal number. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| int | INT | — |
| float | FLOAT | — |
| string | STRING | — |