Nodes/ComfyUI-Random-Int-Divisor-Node/Advanced Random Integer Generator
ComfyUI Node

Advanced Random Integer Generator

Procedural width/height with real guardrails

By Jaminanim·Created 2 years ago·Updated 2 years ago· 0
Advanced Random Integer Generator
    • Width
    • Height
    min_width256
    max_width1024
    width_divisors64
    min_height256
    max_height1024
    height_divisors64
    randomize_widthtrue
    randomize_heighttrue
    maintain_aspect_ratiofalse
    aspect_ratio1.00
    aspect_ratio_basiswidth
    max_aspect_ratio_deviation10.00
    randomization_typeUniform
    gaussian_mean_width512
    gaussian_std_width128
    gaussian_mean_height512
    gaussian_std_height128
    exclude_widths
    exclude_heights
    max_total_megapixels1.00
    max_aspect_ratio_any_direction4.00

    The other two nodes in this pack give you one random number snapped to a divisor. This one is the full version: it generates a random width and height pair with independent ranges, independent divisors, aspect-ratio control, a megapixel cap, and a choice between uniform and Gaussian randomization. If you've ever wanted a procedural "give me a valid resolution" node for batch testing, dataset augmentation, or generative art that varies canvas size every run, this is built for exactly that - the plain divisor nodes are the stripped-down version of the same idea.

    Why this matters more than it looks

    Every diffusion architecture is picky about resolution. SDXL was trained on a handful of specific aspect ratios; Flux wants dimensions divisible by 64; go off-grid on either and you get double heads, elongated bodies, or an outright error. Divisible-by-N resolution pickers are a known, real pattern in the ComfyUI ecosystem - several packs ship their own version. What this one adds is control over the distribution you're randomizing from, not just the bounds.

    How it works

    Width and height are handled almost identically, each with its own min/max, its own divisor field, and its own on/off randomize toggle. Set randomization_type to Uniform (the default) and each dimension is picked flat across its min/max range, then snapped to a multiple of its divisor. Switch it to Gaussian and the matching gaussian_mean_* / gaussian_std_* pair takes over instead, biasing the draw toward a center point rather than spreading evenly - useful for outputs clustered near a target size with occasional outliers.

    Turn on maintain_aspect_ratio and the node tries to keep the pair close to your target aspect_ratio, computed off whichever dimension you set as aspect_ratio_basis, within a tolerance set by max_aspect_ratio_deviation. Independently, max_aspect_ratio_any_direction is a hard ceiling against degenerate results regardless of your other settings, and max_total_megapixels caps total pixel count so a random roll can't hand you a canvas your VRAM (or your model's trained range) can't handle. exclude_widths and exclude_heights let you rule out specific values you've learned to avoid.

    The inputs that matter to a beginner

    Most of the two dozen fields are fine at their defaults until you have a specific reason to touch them. Start with:

    • min_width / max_width / min_height / max_height - your actual working range. Defaults are 256–1024 for both, which is a reasonable SDXL-era spread.
    • width_divisors / height_divisors (STRING, default "64") - note these are strings, not plain integers like on the simpler nodes in this pack. That's usually a sign a field accepts more than one value - most likely a comma-separated list of acceptable divisors to pick between - though the exact syntax isn't documented in the README, so start with a single value like 64 (the safe choice for Flux-class models) before experimenting with a list.
    • randomize_width / randomize_height (BOOLEAN, default true) - flip one off if you want that dimension fixed for the run while the other still rolls.
    • max_total_megapixels (FLOAT, default 1) - the one worth raising immediately if you're targeting SDXL or Flux at ~1024x1024 (roughly 1MP already), since the default is conservative for anything past SD 1.5-era sizes.

    Everything else - the Gaussian params, the aspect-ratio cluster, the exclude lists - is there for when you need finer control, not for a first run.

    Outputs are Width and Height, both INT - wire them straight into an Empty Latent Image, an Empty SD3 Latent Image, or wherever a workflow takes a width/height pair.

    Installing it

    Same pack as the other two nodes here, so the same install path:

    • ComfyUI Manager: search "ComfyUI-Random-Int-Divisor-Node", install, restart.
    • Manual:
      cd ComfyUI/custom_nodes
      git clone https://github.com/Jaminanim/ComfyUI-Random-Int-Divisor-Node
      
      Restart ComfyUI - this node won't appear from a browser refresh alone.

    No extra dependencies beyond ComfyUI itself, and nothing to download.

    Common issues

    • Set max_total_megapixels before relying on this at SDXL/Flux sizes. The default of 1 megapixel sits right at the edge of a 1024x1024 SDXL image, so if your width/height ranges push past that, results may come back smaller than expected - raise the cap deliberately.
    • A divisor bigger than your range leaves nothing valid to land on, same as the simpler nodes in this pack - keep min/max wide enough that a multiple of your divisor actually fits, for both width and height.
    • maintain_aspect_ratio and max_aspect_ratio_any_direction are different guardrails - one steers toward a target ratio, the other just blocks extreme outliers. If output isn't landing near your target ratio, check maintain_aspect_ratio is on; the "any direction" cap alone won't steer for you.
    • This is a small, sparsely documented pack - the README is one paragraph, no field-by-field explanation. When a setting's behavior isn't obvious, test it in isolation rather than guessing from the name alone.
    CategoryCustom/Random

    Inputs (21)

    NameTypeDefaultDescription
    min_widthINT256
    max_widthINT1024
    width_divisorsSTRING64
    min_heightINT256
    max_heightINT1024
    height_divisorsSTRING64
    randomize_widthBOOLEANtrue
    randomize_heightBOOLEANtrue
    maintain_aspect_ratioBOOLEANfalse
    aspect_ratioFLOAT1.00
    aspect_ratio_basisCOMBOwidth2 options: width, height
    max_aspect_ratio_deviationFLOAT10.00
    randomization_typeCOMBOUniform2 options: Uniform, Gaussian
    gaussian_mean_widthINT512
    gaussian_std_widthINT128
    gaussian_mean_heightINT512
    gaussian_std_heightINT128
    exclude_widthsSTRING
    exclude_heightsSTRING
    max_total_megapixelsFLOAT1.00
    max_aspect_ratio_any_directionFLOAT4.00

    Outputs (2)

    NameTypeDescription
    WidthINT
    HeightINT