Nodes/ComfyUI-UtilsCollection/Random Integer in Range
ComfyUI Node

Random Integer in Range

A seeded random integer that stays reproducible across runs

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Random Integer in Range
    • random_integer
    minimum
    maximum
    seed

    You'd think a node that just rolls a number between two values would be the last thing worth writing about, but this one does the one thing ComfyUI's built-in random integers historically don't: it's seeded. UC_IntegerRangeRandom takes a minimum, a maximum, and a seed, and returns a reproducible random integer inside that range. Same seed, same number, every time. That reproducibility is the entire point - it's what lets you iterate on a workflow and then re-run the exact same variation later.

    Reach for it whenever you want controlled chaos: picking a random seed for a sampler, randomizing an image count or a crop index per run, varying step counts across a batch, or building variation into an automation loop where you still want to be able to say "run that again." Because the range is configurable it's genuinely more useful than the fixed random nodes scattered through other packs - you can clamp it to 1..4 for a count, 0..999999 for a seed, whatever.

    How it works

    Under the hood it's a thin wrapper over Python's random.Random(seed).randint(min, max) - a seeded PRNG, not a fresh system roll. Two details in the source are worth knowing:

    • If you accidentally set minimum higher than maximum, it swaps them for you instead of erroring. Nice touch, and it means you never have to think about input order.
    • The seed input has ComfyUI's "control after generate" wired up, so you get the little re-roll icon (the dice button) on the widget. Click it, the seed advances, the output changes. Click it again, and so on - and any seed you land on is still a seed you can lock and reuse.

    Three INT inputs, one INT output (random_integer). There's genuinely nothing else to it, which is the right size for a utility this small.

    Install

    It ships in silveroxides/ComfyUI-UtilsCollection, a ~150-node utility pack by a single active maintainer:

    cd ComfyUI/custom_nodes
    git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
    

    Restart ComfyUI (or use ComfyUI Manager and search "ComfyUI-UtilsCollection"). Dependencies are just opencv-python and typing-extensions - nothing to install separately.

    The one gotcha

    Because the seed is a widget value, changing any widget in the workflow changes the number only if the seed changes - that's what you want. The trap is the reverse: people wire the output into a sampler seed and then wonder why "random" isn't random when they haven't touched the re-roll. If you want true variety per run, you have to advance the seed yourself. If you want variety without reproducibility, this isn't the node - you'd want an unseeded roll. For everything else, it's a tiny, boring, correct tool, and that's a compliment.

    Categoryutils/primitive

    Inputs (3)

    NameTypeDefaultDescription
    minimumINT-9223372036854776000–9223372036854776000
    maximumINT-9223372036854776000–9223372036854776000
    seedINT-9223372036854776000–9223372036854776000

    Outputs (1)

    NameTypeDescription
    random_integerINT