ComfyUI Node

Random Long INT

A fresh random seed on every run — even when you run from the CLI

By ArtemKo7v·Created 27 days ago·Updated 2 days ago· 1
Random Long INT
    • current
    • saved
    last_value0

    ComfyUI's seed workflow has a hole: the "randomize" you see on a KSampler seed widget is a frontend feature. It lives in the browser, fires through control_after_generate, and doesn't exist when you run a workflow headless - from the CLI or an API call. Random Long INT exists for exactly that situation. The pack's own description calls it "random int for cli runs," and that's the honest use case: a node that hands you a fresh, large random integer on every single execution, browser not required.

    Mechanically it's a sibling of the pack's Unix Timestamp node. Both subclass the same stateful base. On each run the node computes a new value - here 1_000_000_000_000_000_000 + secrets.randbelow(...), so anywhere in the upper signed 64-bit range - and exposes it on the current output. The value from before this run sits on saved. A bundled frontend extension writes the new value back into the last_value widget, stored as text so an 18-digit integer survives the workflow JSON round-trip without JavaScript precision loss. On a fresh node, saved starts at 0.

    The one widget, last_value, is write-only bookkeeping - you'll see it on the node but you never type in it. The two outputs, current and saved, are both INT.

    Here's the standard wiring: right-click your KSampler's seed widget and Convert widget to input, then wire current into that socket. Every run rolls a new seed. Because the node forces itself to always run - its IS_CHANGED returns NaN, the same trick every clock and randomizer uses to dodge ComfyUI's cache - the seed genuinely changes run to run. That's the thing a plain widget can't give you in a headless run: a widget holds one value; this gives you a new one every execution.

    Two honest notes. First, the randomness is cryptographic-strength (secrets, not the Mersenne twister random uses) - total overkill for image seeding, but a nice touch and a sign the author cared. Second, the always-run gotcha applies here too: anything downstream of current re-executes every run, so wire the seed input and stop there if that's all you want.

    And saved is the quietly useful one: it's last run's seed. Log it next to your output, or feed it into a text node, so the workflow that made your favorite image can tell you its seed before you hit generate again and roll a new one. The KB calls losing a good seed "the most reliable beginner injury in ComfyUI" - this node gives you an escape hatch from it.

    Install via ComfyUI Manager (search "ComfyUI-UsefulStuffNodes") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ArtemKo7v/ComfyUI-UsefulStuffNodes
    

    Restart ComfyUI and reload the browser tab so the frontend extension loads. Zero dependencies, MIT license, nothing to download.

    CategoryArtemKo7v

    Inputs (1)

    NameTypeDefaultDescription
    last_valueINT0

    Outputs (2)

    NameTypeDescription
    currentINT
    savedINT