Safe Random Seed
The Tiny Node That Stops Random Seeds From Going Negative
- seed
Here's a failure mode you may have met: you set KSampler's seed widget to randomize, queue a bunch of runs, and somewhere in the middle a sampler throws expected non-negative integer and the whole batch dies. The randomize button in the frontend rolls numbers across the full signed 64-bit range, and the SDE-family samplers flat-out refuse negative seeds. Safe Random Seed exists for exactly this: a one-output node that hands your sampler a fresh, never-negative seed on every run.
What it is
Safe Random Seed (class SafeRandomSeed) has no inputs at all and exactly one output: seed, an INT. Drop it in the graph, wire seed into KSampler's seed input, and that's the whole setup. It generates a random seed from 0 to 2^53 - 1 - non-negative, guaranteed - using Python's secrets module, which is the cryptographically-strong generator rather than the predictable one. The number is rolled server-side in the node's Python code, not in the browser.
Two implementation details are worth knowing because they shape how it behaves:
- The node's
IS_CHANGEDmethod returns a fresh random token every call, so ComfyUI re-executes it for every item in the queue. Nothing gets cached; queue 100 runs and you get 100 different seeds, no stale repeats. - After each run the node's title rewrites itself to
Seed: 4897362896, so you can glance at the graph and see exactly what actually ran. That title magic comes from the small JS extension bundled with the pack.
Inputs and outputs that matter
There aren't many, because there's almost nothing to configure:
- Inputs: none.
- Output:
seed(INT). Wire it into KSampler's seed socket, or anywhere else that takes a seed.
One subtlety: if you wire the same node's output into multiple seed inputs, they all get the same value - the node produces one value per execution and fans it out. Want independent seeds for different samplers? Drop a separate Safe Random Seed for each. And since it's a single INT you can also route it through arithmetic nodes if you want derived seeds.
What it deliberately isn't
Safe Random Seed never holds a seed, so it's useless for reproducibility. If you want to lock a seed, type a fixed number into the KSampler widget. If you want a node that remembers what it last ran so you can regenerate or step through, that's rgthree's Seed node - different job entirely. This node's entire personality is "give me a new, safe, random integer every single run."
That fixed-seed discipline matters for debugging too: randomize-everything makes it impossible to tell what changed between two images. Use this node when you want variation, not when you're trying to diagnose one.
Installing it
Nothing heavy here - the pack has zero dependencies (empty dependencies = [] in its pyproject, no requirements.txt, no model downloads). Either way you install, then restart ComfyUI:
- ComfyUI Manager: search for
ComfyUI-PromptRandomChoiceand install. - Manual:
cd ComfyUI/custom_nodes git clone https://github.com/ruminar/ComfyUI-PromptRandomChoice
It's GPL-3.0 licensed, same as ComfyUI itself.
Common issues
- Title not updating to
Seed: …: the title rewrite runs in the browser extension, so it needs the frontend to have loaded the pack's JS. Restart ComfyUI and hard-refresh the browser if the old title sticks. - You expected the seed to be stable and it isn't: read "what it deliberately isn't" above - you grabbed the wrong tool, not a bug.
- Downstream reruns every queue item: that's the intended no-cache design, and it's what you want for variation batches. Just don't put an expensive model load downstream of it and wonder why it runs 100 times.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| seed | INT | — |