ComfyUI Node

Dynamic Random Number Node

A random integer that's different on every run

By inkbottle-9·Created 8 months ago·Updated 12 days ago· 1
Dynamic Random Number Node
    • random_int
    min0
    max10

    A node that rolls a random integer between a min and a max, and rolls a new one every single execution. That's it - but "every single execution" is the entire point, and it's also the trap.

    You'll reach for it when you want variety without touching anything: a random seed, a random batch size, or - the classic combo - a random index feeding this pack's DynamicSwitchAnyNode to pick a random prompt or model case per run. ComfyUI's built-in seed widgets already randomize, but they only randomize seeds. This gives you any integer in any range you define, as a plain INT that any node can consume.

    How it works

    Two inputs, both integers:

    • min - inclusive lower bound (default 0).
    • max - upper bound (default 10).

    One output: random_int. Roll the dice, get an INT, wire it anywhere.

    Two details from the source are worth knowing because they bite:

    • max is actually inclusive. The tooltip says "exclusive," but the implementation uses Python's random.randint(min, max), which includes both ends. min=0, max=10 can hand you a 10. If you need a true 0–9, set max to 10 anyway and live with the occasional 10 - or set max to 9. Test it before you trust it.
    • It swaps reversed ranges for you. Feed it min=10, max=0 and it quietly flips them rather than erroring. Nice touch, but don't rely on it - set the range right.

    The gotcha: it's always dirty

    The node opts out of ComfyUI's execution cache - its change-detection returns NaN, the "not equal to anything, even itself" trick that forces a rerun. That's exactly what you want from a random node; if it cached, you'd get the same number forever. But the same flag marks everything downstream dirty, so a random node feeding a big sampler branch means that whole branch re-executes every run, every time, whether its other inputs changed or not. One random value at the top of a heavy pipeline quietly disables the cache for the pipeline. Use it where you actually want randomness, and don't scatter them around a workflow as "free variety" - each one costs you.

    Related gotcha: because it reruns constantly, you can't reproduce a run by its widgets. The number is fresh every execution, so if you need a repeatable draw, capture the output (into a primitive or a saved value) rather than trying to read the node's own state back.

    Install

    It ships in comfyui_dynamic, the zero-dependency solo pack - you're getting it whether you wanted the script executor or not:

    cd ComfyUI/custom_nodes
    git clone https://github.com/inkbottle-9/comfyui_dynamic.git
    

    then restart ComfyUI, or install comfyui_dynamic from ComfyUI Manager. Small pack, rough edges, but for "give me a random integer each run," this node does exactly one thing and does it correctly.

    Categorydynamic/math

    Inputs (2)

    NameTypeDefaultDescription
    minINT0The minimum value (inclusive) of the random number
    maxINT10The maximum value (exclusive) of the random number

    Outputs (1)

    NameTypeDescription
    random_intINTA random integer between min and max.