ComfyUI Node

随机图片

Pick a random image from the ones already in your graph

By mango-rgb·Created 2 years ago·Updated 2 years ago· 2
随机图片
  • image1
  • mask1
  • image2
  • mask2
  • image3
  • mask3
  • image4
  • mask4
  • image5
  • mask5
  • image
  • mask
sort_mode
seed0

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.

Category🥭 芒果节点/图片

Inputs (12)

NameTypeDefaultDescription
sort_modeCOMBO2 options: 完全随机, 顺序循环
seedINT00–18446744073709550000
image1optIMAGE
mask1optMASK
image2optIMAGE
mask2optMASK
image3optIMAGE
mask3optMASK
image4optIMAGE
mask4optMASK
image5optIMAGE
mask5optMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK