Random Empty Latent
Keep the Megapixels, Roll the Aspect Ratio
- latent
- width
- height
SDXL was trained at 1024×1024 plus a short list of fixed ratios, and most of today's models still live in a comfortable megapixel band - roughly 1–2MP. What keeps quality stable isn't the exact width and height, it's the total pixel area. So the smart way to farm variation is to hold the pixel count constant and let the aspect ratio roll. That's exactly what Random Empty Latent does: it's EmptyLatentImage with a die.
How it works
It's a tiny node, and the source is easy to read. Your seed feeds Python's random.Random(seed) - deterministic, so the same seed always rolls the same ratio. That ratio is drawn uniformly from the range you set, then the node solves for width and height so the total area lands near your pixel_count:
width(in latent units) ≈ sqrt ofpixel_count × ratio / 64height= width ÷ ratio- the latent it hands you is
(batch_size, 4, height, width)of zeros
Zeros, like EmptyLatentImage - the KSampler adds the actual noise later. The node returns the real pixel dimensions at 8× the latent size, which is what the width/height outputs report.
One thing to internalize: this seed is not the KSampler seed. It only decides the aspect ratio. Set it and it deterministically picks the same dimensions; it has nothing to do with what the image ends up looking like.
The inputs that matter
Four of the five are worth touching:
- pixel_count - your megapixel budget. Default 1048576 (1024²), range 512² to 2048². The single knob that keeps you in the model's comfort band.
- min_ratio / max_ratio - the aspect range, 0.1 to 10. Both default to 1, which is just a square; widen them and the fun starts. The node refuses to run if max is below min.
- seed - rolls the ratio. Lock it to reproduce a specific dimension set.
- batch_size - number of latents, up to 4096. Note the whole batch shares one ratio.
Outputs: latent (LATENT) wires into your sampler, and width/height (INT, in pixels) go to anything that needs the real size - an empty conditioning, an upscale target, a text box you want to announce the dims in.
Why you'd actually use it
A classic: set min_ratio 0.75, max_ratio 1.5, batch 8, and get eight images at eight different aspect ratios, all roughly 1MP, in one queue pass. For a training dataset, a seed-farming session, or just breaking out of "everything is square," that beats hand-plugging a dozen fixed dimensions. The constant-megapixel trick is quietly the right way to do aspect variety, and this node packages it in one.
Gotchas
- Rounding. Width and height are rounded to whole latent units, so actual area isn't exactly your pixel_count and the effective ratio drifts a little from the range you set. Fine for farming, maddening if you need exact dimensions.
- Whole batch, one ratio. If you want each image different, vary the seed per batch or run separate nodes.
- It tells you the size, not the ratio. The width/height outputs are your only read on what it rolled.
Installing it
Same pack as the Eval node, same trivial install - no dependencies, no models:
cd ComfyUI/custom_nodes
git clone https://github.com/changwook987/ComfyUI-Small-Utility
Restart ComfyUI, and it's under the "latent" category. ComfyUI Manager users can search "ComfyUI-Small-Utility" and click install. The pack also adds right-click "SDXL Sizes" on EmptyLatentImage and "sort prompt" on any node, if you're curious.
Verdict
Small, focused, and genuinely nice - the kind of node that doesn't generate anything itself and still earns its place. It's one of the first things I'd grab from this pack.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| seed | INT | 00–18446744073709550000 | — |
| pixel_count | INT | 1048576262144–4194304 | — |
| min_ratio | FLOAT | 1.000.1–10 | — |
| max_ratio | FLOAT | 1.000.1–10 | — |
| batch_size | INT | 11–4096 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |
| width | INT | — |
| height | INT | — |