Nodes/comfyui_gr85/Random Ratio
ComfyUI Node

Random Ratio

Sampling a random aspect ratio between two bounds

By veighnsche·Created 2 years ago·Updated 8 months ago· 1
Random Ratio
    • width
    • height
    seed0
    first_width1
    first_height1
    second_width1
    second_height1

    Straight from the README: Random Ratio takes two width/height pairs and samples a random aspect ratio somewhere between them, seeded, returned as integer width/height components. Think of it as randomizing shape rather than size - instead of hardcoding "this batch is always 16:9," you give it a range (say, 1:1 at one end and 16:9 at the other) and let it pick somewhere in between per seed, so a batch comes out with varied but bounded compositions instead of one fixed rectangle every time.

    It's filed under GR85/Latent for a reason: the natural destination for its output is an EmptyLatentImage or one of the resolution-helper nodes elsewhere in the pack.

    Inputs. seed - the usual determinism knob, full 64-bit range (0 to roughly 1.84×10¹⁹). first_width/first_height and second_width/second_height are your two bounding aspect ratios (1–4096 each, default 1 across the board). Set these deliberately - the defaults are all 1, which is a degenerate 1:1-only range, so if you don't touch them you'll always get a square regardless of seed. Outputs are width and height.

    Read the outputs as a ratio, not a resolution. This is worth being explicit about because it's easy to assume otherwise: the README's own language for a related node (GR85_ImageSizerAll, not covered here) describes exactly this kind of output as "aspect ratio components," fed alongside a separate pixel budget to produce real, snapped dimensions. Random Ratio's width/height are small numbers bounded 1–4096 - they encode a shape, not a target canvas size. If you want an actual usable resolution for a KSampler's latent, pair this with a proper resolution node (the pack's own ImageSizer/ImageSizerAll, or hand-roll a multiply-and-snap step) rather than piping the raw output straight into EmptyLatentImage and hoping for sane pixel counts.

    Worth noting, too: this lives in the same corner of the pack as GR85_ImageDimensionResizer, GR85_ImageSizer and GR85_ImageSizerAll - the README's "Resolution helpers" group - which aren't part of this batch of articles but are the natural next stop if aspect-ratio randomization is only step one of what you're building.

    Installing it. No dependencies beyond the pack itself. Search "comfyui_gr85" in ComfyUI Manager, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/veighnsche/comfyui_gr85
    

    Restart ComfyUI.

    Where people get tripped up. Leaving the two bound pairs at their 1/1/1/1 defaults and wondering why the output "isn't random" - it is, there's just nothing to be random between. And feeding the raw output directly into a latent node without a snap-to-multiple-of-8 (or 64, for some models) step downstream - like most manually-computed resolutions in ComfyUI, an unsnapped width or height can produce artifacts or an outright shape error depending on your model architecture.

    CategoryGR85/Latent

    Inputs (5)

    NameTypeDefaultDescription
    seedINT00–18446744073709550000
    first_widthINT11–4096
    first_heightINT11–4096
    second_widthINT11–4096
    second_heightINT11–4096

    Outputs (2)

    NameTypeDescription
    widthINT
    heightINT