随机图片
Pick a random image from the ones already in your graph
- image1
- mask1
- image2
- mask2
- image3
- mask3
- image4
- mask4
- image5
- mask5
- image
- mask
RandomImageNode is the odd one out in the Mango Random pack. Its siblings read from disk; this one works on images you've already loaded into the graph. Connect up to five images (each with an optional mask), pick a mode, and it outputs one image plus its mask. It's the "switch on a random channel" node for img2img, inpainting, and style-comparison workflows - no filesystem involved.
That distinction matters. If your images live in a folder, you want the sibling RandomImagePathNode, which loads straight off disk. RandomImageNode is for when upstream nodes are already producing IMAGE tensors: a batch of candidates from a LoRA comparison, a few frames out of a VHS node, several variants from a prior pass. Everything flows through wires, nothing touches disk.
Inputs and outputs that matter
- sort_mode - the Chinese-labeled dropdown again: 完全随机 (fully random) or 顺序循环 (sequential cycle).
- seed - INT, default 0. In random mode the node reseeds with it, so a fixed seed means a fixed pick; bump it to roll again.
- image1 through image5, each with a matching mask1 through mask5 - optional IMAGE and MASK pairs. Masks aren't required: if a slot has an image but no mask, the node fabricates an all-white mask so the output is always a valid pair.
- image and mask outputs - both real tensors, wired into anything downstream that eats IMAGE/MASK: an inpainting node, an img2img sampler, a ControlNet preprocessor.
One subtle behavior worth knowing: if a connected image is a batch (more than one frame in a single tensor), the node splits it - each frame becomes its own entry in the pool. So a 4-frame batch from a video node fills four slots' worth of candidates, not one. That can surprise you if you expected the whole batch treated as a single unit.
How to install
Same pack, same install. ComfyUI Manager: search "Mango Random Nodes", Install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/mango-rgb/ComfyUI-Mango-Random-node
then restart. No model downloads. Like the rest of the pack, it's dependency-light - the requirements.txt deps (opencv-python, imageio-ffmpeg) are for the video node, not this one.
Common issues and gotchas
The node errors out with a ValueError if you queue it with no images connected - same "needs at least one input" guard as the text node. And remember the seed rule: with a fixed seed, random mode returns the same image every run. That's deterministic selection, which is genuinely useful when you want to rerun a workflow with the same candidate. To shuffle, advance the seed.
Also keep the mask pairing in mind: masks attach to their slot, and in sequential mode the walk is over the flattened pool of images and their masks stay glued together - you always get a matched image/mask pair out. That makes it a decent quick source for inpaint roulette: feed it a few image+mask pairs, let it pick one, run.
It's a niche node - you'll reach for it far less often than its text sibling - but when you need "one of these five images, at random, without touching disk," it's the exact tool.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| sort_mode | COMBO | 2 options: 完全随机, 顺序循环 | |
| seed | INT | 00–18446744073709550000 | — |
| image1opt | IMAGE | — | |
| mask1opt | MASK | — | |
| image2opt | IMAGE | — | |
| mask2opt | MASK | — | |
| image3opt | IMAGE | — | |
| mask3opt | MASK | — | |
| image4opt | IMAGE | — | |
| mask4opt | MASK | — | |
| image5opt | IMAGE | — | |
| mask5opt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |