Load Random Images
A random image from a folder, whenever you need one
- image
- mask
- image_path
"Load a random image from a folder" sounds like a two-second job in ComfyUI, and it isn't. There's a whole genre of r/comfyui thread where people try to bolt math nodes onto the core Load Image and end up with something that "just randomizes the start of the list" instead of picking a truly random file. Load Random Images, from the MoneyMaker pack (display name ComfyUI-Yuan), is one author's answer to that exact annoyance. You point it at a folder, it hands you one or several random images plus their masks and paths.
How it works
Under the hood it's short and straightforward: it lists the folder you give it, keeps only .jpg, .jpeg, .png and .webp files, sorts them by the first number in the filename (so img_12.png sorts before img_103.png), then picks randomly. Each picked file is loaded, EXIF-rotated, and converted to RGB.
The selection logic is worth knowing because the image_load_count input has three modes, not one:
1- one image, picked withrandom.choice.- Between 2 and the file count - a
random.samplewithout replacement, so no repeats in the same run. - Equal to or larger than the file count - everything in the folder, in sort order.
So the count is really a cap: it never loops, it never repeats within a run, and it tops out at "all files." That makes it usable as a mini batch sampler, which is the niche it actually fills.
The inputs that matter
- folder - an absolute path like
D:\refs\animeor/home/user/pics. There's no file browser; you type it. Note it does not default to ComfyUI's input directory - it reads whatever path you type, so typos surface as aFolder ... cannot be founderror. - image_load_count - the count/cap described above.
- seed - here's the trap. The tooltip says "The random seed used for creating the noise," but the code never actually uses it to pick anything. Selection runs on Python's global
randommodule, so the seed input is decorative. Want reproducible picks? This isn't your node; re-running just gives you a fresh roll.
Outputs are three lists - image, mask, and image_path - which is what you'd wire into an img2img or style-transfer chain. That's the realistic use case: pull a random reference, run it through img2img, and get a different flavor every queue. It's also handy for sampling a validation folder when you're testing a checkpoint.
Gotchas to know before you're confused
- The mask is inverted alpha (
1 - alpha) for images that have one. For images without an alpha channel you get a fixed 64×64 zero tensor - and that tensor is created withdevice="cuda", so a CPU-only ComfyUI install can trip here. Either way the mask won't match your image's dimensions, so don't expect to use it as a resize-accurate matte. - The source returns a fourth value (the seed) that isn't declared in the output schema. Depending on your ComfyUI version that's either ignored or a return-count error - either way the seed output you might expect never exists.
- Outputs are lists, so downstream nodes need to accept them (or you pipe them into something that does). That's normal ComfyUI behavior for list outputs, just don't plug a single-IMAGE input straight in and wonder why it sees a batch.
Install
It ships in the MoneyMaker pack, which Manager finds as ComfyUI-Yuan (that's the pack title). In ComfyUI Manager: Install Custom Nodes → search "Yuan" or "MoneyMaker" → install → restart. Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/Cyber-BlackCat/ComfyUI-MoneyMaker
Then restart ComfyUI. There are no model files to download - this is pure image handling. The heavy additions are opencv-python and scikit-image (plus the usual torch/numpy/pillow you already have); opencv-python is the one that can take a minute on Windows. The repo also ships an example workflow and a couple of demo images under example_workflows/ if you want to see the intended setup.
One last thing: it's a small, low-traffic pack from an individual author (the category shows up as MoneyMaker😺 - that's intentional). It works fine for the job above, but if you need something battle-tested for big folder-driven workloads, WAS Node Suite's image batch loader is the more established neighbor. For a quick random reference roulette, this does the trick.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| folder | STRING | — | |
| seed | INT | 00–18446744073709550000 | The random seed used for creating the noise. |
| image_load_countopt | INT | 1 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| image_path | STRING | — |