Advanced Random Integer Generator
Procedural width/height with real guardrails
- Width
- Height
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 like64(the safe choice for Flux-class models) before experimenting with a list. - randomize_width / randomize_height (
BOOLEAN, defaulttrue) - 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:
Restart ComfyUI - this node won't appear from a browser refresh alone.cd ComfyUI/custom_nodes git clone https://github.com/Jaminanim/ComfyUI-Random-Int-Divisor-Node
No extra dependencies beyond ComfyUI itself, and nothing to download.
Common issues
- Set
max_total_megapixelsbefore 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_ratioandmax_aspect_ratio_any_directionare different guardrails - one steers toward a target ratio, the other just blocks extreme outliers. If output isn't landing near your target ratio, checkmaintain_aspect_ratiois 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.
Inputs (21)
| Name | Type | Default | Description |
|---|---|---|---|
| min_width | INT | 256 | — |
| max_width | INT | 1024 | — |
| width_divisors | STRING | 64 | — |
| min_height | INT | 256 | — |
| max_height | INT | 1024 | — |
| height_divisors | STRING | 64 | — |
| randomize_width | BOOLEAN | true | — |
| randomize_height | BOOLEAN | true | — |
| maintain_aspect_ratio | BOOLEAN | false | — |
| aspect_ratio | FLOAT | 1.00 | — |
| aspect_ratio_basis | COMBO | width | 2 options: width, height |
| max_aspect_ratio_deviation | FLOAT | 10.00 | — |
| randomization_type | COMBO | Uniform | 2 options: Uniform, Gaussian |
| gaussian_mean_width | INT | 512 | — |
| gaussian_std_width | INT | 128 | — |
| gaussian_mean_height | INT | 512 | — |
| gaussian_std_height | INT | 128 | — |
| exclude_widths | STRING | — | |
| exclude_heights | STRING | — | |
| max_total_megapixels | FLOAT | 1.00 | — |
| max_aspect_ratio_any_direction | FLOAT | 4.00 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Width | INT | — |
| Height | INT | — |