Nodes/comfy-ovum/_.random
ComfyUI Node

_.random

A Random Integer With an Off-by-One You Should Know About

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.random
  • obj
  • max_number
  • *

_.random rolls a random integer between a min and a max. It sounds like the most boring node in the pack, and it mostly is - except for one detail the description gets wrong: the max isn't actually inclusive. That's the kind of off-by-one that silently gives you subtly wrong batches of random values, so it's worth knowing before you trust it.

How it works

Under the hood it's Python's random.randrange(min, max). And randrange's stop value is exclusive. So:

  • _.random with min 5, max 10 returns something from 5 through 9 - never 10
  • min 0, max 1 returns only 0
  • The "random integer between min and max (inclusive)" in the description is just wrong about that last number

I ran it to confirm: random(0, 1) returns 0 every time. If you genuinely need the inclusive upper bound, add one to your max before feeding it in - random(0, 10) with max set to 11 gives you 0 through 10.

The inputs:

  • obj - the minimum (or a _.CHAIN)
  • max_number - the maximum

Output: an integer in the range.

The reproducibility catch

Bigger caveat: this uses Python's global random module, not ComfyUI's seedable random. There's no seed input, so two runs won't match, and nothing about the workflow seed controls it. For anything where you might want to reproduce a result - choosing a prompt variant, a test image, a starting value - _.random is the wrong tool. That's what the pack's seed and counter nodes are for. _.random is for when you genuinely want non-determinism: a random pick for an A/B test, a jittered value, a throwaway choice.

Where it sits

The signature is a little odd because it's a faithful port of the JS method: in JS, _.random(5, 10) reads naturally, but here the min comes from the primary input slot (which also accepts a chain) and the max from the second. If you leave max_number unplugged, random(min) rolls from 0 to min - 1 - again exclusive. Feed it numbers and don't overthink the labels.

Installing

Part of comfy-ovum. ComfyUI Manager → search comfy-ovum → Install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart ComfyUI. No models, no extra pip packages for the underscore nodes - the port is bundled in the repo.

The bottom line

A simple random integer, with an exclusive max that contradicts its own description, and no seed control. Add one to your max if you want it inclusive, and keep it away from anything you need to reproduce.

Categoryovum/underscore

Inputs (2)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.
max_numberopt*max_number: JSON allowed for arrays/objects where applicable.

Outputs (1)

NameTypeDescription
**