ComfyUI Node

Random Integer

Seed-aware randomness for your graph

By wenchengxiang·Created about a month ago·Updated a day ago· 1
Random Integer
    • int_value
    min_value0
    max_value100
    seed0

    Random Integer gives you a random whole number between a min_value and a max_value, with a seed, and outputs it as a proper INT. That's a small thing, but ComfyUI has a genuinely annoying hole here: the seed you already know - the KSampler's - is attached to noise generation, and there's no clean core primitive for "give me a random number I can use as a parameter." This node fills exactly that gap.

    Where it pays off: any workflow where a number doubles as a knob. Randomize the batch count within a range. Pick a random strength for img2img between 0.3 and 0.8. Drive an XY-plot axis or a prompt-switch index with a random pick each run. Feed it into a math node to derive a random CFG or steps. The moment you find yourself typing a value and thinking "I wish this rolled a new number each run," this is the node.

    The seed is the star, and it's worth understanding because it's also the trap. Unlike random.randint you might call in a script, this node seeds Python's random generator with your seed value first - so the same min, max, and seed always produce the same integer. That's the "reproduce a good run" property, and it's exactly how the KSampler seed behaves. The widget's seed field also defaults its control_after_generate to randomize, so it rolls a fresh seed after each run. That means: if you find a good image and want to lock in the other random values that produced it, remember that the number in the box is what ran last - the known control_after_generate footgun from the plumbing layer, applied here. Set the dropdown to fixed before you change anything else.

    How it works

    Nothing exotic: it calls random.seed(seed), then random.randint(actual_min, actual_max). The one thoughtful detail in the source is that it swaps min and max if you accidentally set them backwards - min_value=100, max_value=1 silently becomes a range of 1 to 100 instead of erroring. Most nodes would just break; this one shrugs.

    The inputs and outputs that matter

    • min_value - lower bound, default 0. Integer.
    • max_value - upper bound, default 100. Both ends are inclusive, so with defaults you get 0–100.
    • seed - default 0, with control_after_generate set to randomize. The reproduction key: same seed + same range = same result.
    • int_value (output) - the random integer, as a standard INT socket that plugs into any numeric input.

    How to install it

    Part of ComfyUI-Practical-Tools by wenchengxiang. ComfyUI Manager → search ComfyUI-Practical-Tools → install → restart. Manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools
    

    No dependencies beyond the standard library and what ComfyUI already provides.

    Common issues

    • "It keeps changing and I can't go back." That's control_after_generate on randomize doing its job. Flip the seed's dropdown to fixed when you've hit a combination you like.
    • Not reproducible across ComfyUI versions. The seed ties to Python's random, which is stable in practice, but this is not the KSampler's noise seed - it won't reproduce an image by itself, only the integer. If your goal is pixel-identical output, you still need the sampler's own seed.
    • Range sanity. Both endpoints are inclusive and the node handles inverted ranges for you, but it will happily generate a huge number if you ask for one - there's no clipping.
    CategoryPractical-Tools/utils

    Inputs (3)

    NameTypeDefaultDescription
    min_valueINT0-18446744073709550000–18446744073709550000
    max_valueINT100-18446744073709550000–18446744073709550000
    seedINT00–18446744073709550000

    Outputs (1)

    NameTypeDescription
    int_valueINT