Nodes/comfy-ovum/_.sampleSize
ComfyUI Node

_.sampleSize

Grab n random items, re-rolled every run

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.sampleSize
  • obj
  • guard
  • LIST
n1

_.sampleSize reaches into a list and pulls out n random elements - no repeats, drawn from unique positions. Ask for 2 out of ["red","green","blue","yellow"] and you might get ["blue","red"]; ask for 5 out of 4 and you get all 4, because the sample is capped at the size of the collection. It's the graph-shaped version of "roll a random subset."

This is one of the more genuinely useful members of the ovum/underscore family in comfy-ovum, which wraps underscore3 (a Python port of Underscore.js, bundled in the pack). Where it earns its keep: picking a random prompt variant from a list, choosing a random seed set, sampling a few LoRA names out of a stack, or building randomized A/B batches. In a generative workflow, "random subset of things" is a real recurring need, and this is a one-node answer.

The randomness caveat

Because it uses Python's random module, every execution rolls fresh - unless ComfyUI decides the node's output is cached and skips re-running it. If your sampled list refuses to change between runs, the cause is output caching, not the node; force re-execution (queue again with the cache busted, or toggle the node's cache handling) to re-roll. That's a property of the whole family, not a bug in this one, but it bites harder here because randomness is the entire point.

Inputs and output

  • obj (*) - the collection to sample from. Lists, tuples, sets, even dicts (values get sampled).
  • n (INT, default 1) - how many elements you want. The tooltip calls it n (int). Keep it >= 1; values larger than the collection are clamped.
  • guard (*) - a leftover from the JS signature used to make the method work as an iteratee. You can ignore it.

Output is a LIST. Note the subtle difference from _.take: _.take returns the first n; _.sampleSize returns n random ones. And unlike _.shuffle, the result is a subset, not a full reorder.

Install

# via ComfyUI Manager: search "comfy-ovum"
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
# restart ComfyUI

No model downloads; pure Python. Manager installs the pack's declared dependencies (aiohttp, pillow, numpy, requests, etc.) and underscore3 comes bundled in the repo. The author's README flags the underscore family as work in progress and not for production - for a randomizer this matters less, but if you need reproducible random selection (same subset every run for testing), you'd have to drive it yourself; there's no seed input here.

Categoryovum/underscore

Inputs (3)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.
noptINT1n (int)
guardopt*guard: JSON allowed for arrays/objects where applicable.

Outputs (1)

NameTypeDescription
LISTLIST