ComfyUI Node

Seed

The fix for ComfyUI's worst default, and why -1 breaks your API calls

By lany42·Created 22 days ago·Updated a day ago· 1
Seed
    • SEED
    ◄seed-1►

    Everyone gets burned by ComfyUI's seed widget exactly once, and it's never their fault. You roll a great random seed, flip the dropdown to fixed to keep it, and the seed is already gone - because control_after_generate fires after the run, so the number sitting in the box is the one that will be used next, not the one that made the image. The community's read on it is unanimous and slightly bitter: "It's rather annoying when you get a good seed, forgot you didn't change the setting, and then go to change a value and get an entirely different image" (1l604gp, +22).

    Seed is one answer to that. It's a standalone integer source, in the spirit of rgthree's Seed node, that hands one seed to every sampler, filename and metadata field in the graph - with modes and buttons that assume you will change your mind.

    How the modes work

    The single input is seed: an INT, default -1, min -3, max 9007199254740991 (that's 2^53−1, JavaScript's safe-integer ceiling - the pack works in that range on purpose, because the frontend is what resolves the value).

    • -1 randomizes
    • -2 increments the last queued seed
    • -3 decrements it
    • anything ≥ 0 is used as-is

    It also has randomize, new seed and use last seed buttons, and stepping wraps within the seed range (incrementing at the ceiling drops to 0).

    Here's the mechanism worth understanding, because it's the source of the one real gotcha. The resolver lives in the pack's browser-side JavaScript, not in Python. When you queue a prompt, the frontend turns -1, -2 or -3 into a concrete number before submission. The Python node refuses to guess: it raises if it's handed -1, -2 or -3. Which means if you drive ComfyUI through the API - a script, another app, a hosted wrapper - and send -1, the run fails instead of randomizing. Bypass the mode logic and send a real integer, or resolve the random number on your side.

    The flip side is the nice bit: because the resolution happens at queue time, the seed in the box is the one that just ran, and use last seed gets you back to it without touching a PNG.

    Wiring it

    SEED is a plain INT output. Convert a sampler's seed widget to an input and plug it in - one seed, five samplers, consistent. The same output feeds ImageSaverMini's seed field, and if you use %seed in a save filename you get the number in the filename too. This is the "one value, many consumers" pattern that the whole primitive-node family exists for; the difference here is the modes.

    The control widget also carries no control_after_generate dropdown at all, which is the point. There's no hidden second setting that can silently eat your seed at the end of the run.

    Install

    cd /path/to/ComfyUI/custom_nodes
    git clone https://github.com/lany42/comfyui-lany-nodes.git
    # restart ComfyUI
    

    Manager users: search comfyui-lany-nodes (listed as "ComfyUI Lany Nodes"). No model downloads, no extra deps beyond numpy and Pillow. Two things to know before you install: the pack needs Python 3.13+ and a ComfyUI new enough to have the V3 node API, and Seed specifically needs the browser side. If the pack's frontend scripts don't load - you reinstalled the folder, or you're mid-frontend-update and the browser is serving cached JS - the modes stop resolving and you get the backend's "Seed modes -1, -2, and -3 require the ComfyUI browser controls" error. Hard-refresh the tab before you go filing issues.

    If it misbehaves

    -2/-3 need a previously queued seed to step from; with none, -1 and -2 fall back to a fresh random and -3 decrements from whatever the last seed was. So the first run of a batch is always effectively random - don't try to use it as a counter from a cold start. If your seeds stopped changing between runs, something upstream is reusing a cached execution: the node is only re-read when the prompt is actually queued.

    If you want the general version of this fix rather than a node, it's a one-time setting - switch widget control mode from After to Before in ComfyUI's settings and the built-in seed boxes stop lying to you too. Do that either way.

    CategoryLany Nodes

    Inputs (1)

    NameTypeDefaultDescription
    seedINT-1-3–9007199254740991—

    Outputs (1)

    NameTypeDescription
    SEEDINT—