Nodes/ComfyUI-EqualRandomInteger/Equal Random Integer
ComfyUI Node

Equal Random Integer

Equal Random Integer

By Lingyuuuux·Created 4 months ago·Updated 4 months ago· 0
Equal Random Integer
    • value
    minimum0
    maximum5

    ComfyUI has a dirty secret that bites every beginner eventually: it caches node outputs. Run the same graph twice and nodes with identical inputs don't re-execute - they hand back the last result. That's great for efficiency and terrible for anything "random", because a random node that forgets to opt out of caching returns the same value every run. Enter Equal Random Integer, a two-input utility node whose entire job is giving you one uniformly chosen integer - and refusing to let ComfyUI freeze it in place.

    Why you'd reach for it

    Seed farming, mostly. The standard community loop for finding a good seed is to fix everything and rerun with a random seed until one lands well (the KB's own advice is "change one variable at a time with a fixed seed" - which presupposes you can randomize the seed). Drop this node's value output into a sampler's seed input and every run rolls a fresh seed for you. Beyond that, it's the general "randomize an integer" workhorse: random width/height for batch variation, random LoRA strength, random steps. Anywhere a workflow needs to be different each time it runs, this is the node. It's not glamorous, but it's the kind of composability that makes ComfyUI worth fighting with.

    How it works

    The mechanism is refreshingly honest. The node picks value = minimum + secrets.randbelow(span) where span = maximum - minimum + 1. Two details matter here.

    First, it uses Python's secrets.randbelow() rather than random.randint(). That's the crypto-grade generator, and crucially it avoids modulo bias - a naive random.randint over a non-power-of-two range skews the distribution slightly. For picking seeds, the bias is negligible in practice; for the author's claim of "equal probability", it's the correct choice.

    Second, and this is the part most similar nodes get wrong: it overrides IS_CHANGED to return NaN. In ComfyUI, IS_CHANGED returning a non-deterministic value tells the executor "never cache this - recompute every queue run." That's the entire difference between a working random node and one that gives you the same seed forever and makes you think you're cursed.

    The inputs and output

    Only two inputs, both integers, and you'll set both:

    • minimum - inclusive lower bound (default 0)
    • maximum - inclusive upper bound (default 5)

    Inclusive is the gotcha: set minimum 0 and maximum 4 and you get five possible values (0–4), not four. The output is a single value of type INT - wire it into any integer slot, most commonly a sampler seed or a batch count.

    Install

    This pack is about as light as custom nodes get: one file of stdlib Python, no requirements.txt, no models, no weights, nothing to download. The README's official route is copying the folder into ComfyUI/custom_nodes/, which is the same thing a clone does:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Lingyuuuux/ComfyUI-EqualRandomInteger
    

    Then restart ComfyUI. ComfyUI Manager should also find it by the pack title if you'd rather click through the registry. From there it lives under the jieidan/random category, named Equal Random Integer.

    Gotchas

    • Minimum above maximum is a validation error ("minimum must be less than or equal to maximum"), and the node raises rather than silently clamping. Flip them if you get a red node.
    • It's an INT. If your target slot wants a float, route value through an INT→FLOAT conversion node first.
    • It's random on purpose. If you embed this in a workflow you share, every downloader gets different results per run - which is the point when you're seed farming, and a nightmare when you're debugging. Remember the golden rule: lock the seed, change one thing at a time.

    If all you need is "a number that actually changes each run," this is the one to reach for. It does exactly what the name says, and nothing else.

    Categoryjieidan/random

    Inputs (2)

    NameTypeDefaultDescription
    minimumINT0-2147483648–2147483647
    maximumINT5-2147483648–2147483647

    Outputs (1)

    NameTypeDescription
    valueINT