Nodes/ComfyUI-mnemic-nodes/🎲 Random Int in Range
ComfyUI Node

🎲 Random Int in Range

Roll an Integer for Steps, Batch Size, or Anything Else

By MNeMoNiCuZΒ·Created 3 years agoΒ·Updated a day agoΒ· 105
🎲 Random Int in Range
    • random_int
    β—„min_value0β–Ί
    β—„max_value100β–Ί
    β—„seed-1β–Ί

    You want a batch where the step count wanders between 18 and 34 instead of being nailed to 24. Or a batching setup where each run picks a different batch_size. 🎲 Random Int in Range is the boring workhorse for that: give it a min and a max, it gives you an integer inside those bounds, inclusive, every execution.

    Paired with the rest of the pack, it's how you get settings variance without hand-editing widgets between queues. Randomising settings is a genuinely underrated trick - the wildcard folks randomise prompts and then run every one at CFG 7 and 20 steps, which means every twelve-of-twenty images has the same flat, overcooked look because the settings never varied.

    How it works

    min_value and max_value are inclusive integers and the range is huge - the inputs go to Β±2^64, so you can roll a seed-sized value if you want. If you accidentally put the bigger number first, don't worry: the node swaps them for you rather than erroring or returning an empty range.

    seed is optional and defaults to -1. Give it a real value and it rolls from a seeded generator, so the result is reproducible; leave it at -1 and it draws from Python's unseeded RNG. As with the rest of the pack's random nodes, -1 means "different each time it executes", and ComfyUI's cache decides whether it executes - if nothing upstream changed, the value can be reused from cache. The pack's plain Random Seed node forces a re-run with a time.time() fingerprint; this one doesn't. If you need guaranteed variance per queue, drive the input or set a seed and increment it.

    Inputs and outputs

    Two required inputs, min_value (default 0) and max_value (default 100), one optional seed. A single output, random_int, typed INT.

    Where it actually earns its place: convert a widget to an input and feed it. Steps on the KSampler is the obvious one, but any integer widget works - batch_size on an Empty Latent, a start/end step pair for a partial denoise, a blur radius, a tile size in a tiling upscale.

    Be sensible about the range, though. Rolling steps between 5 and 60 in one batch gives you six unusable images and four good ones, and you can't tell which is which without reading the metadata. Between 20 and 30 is a test you can actually learn something from.

    Install

    ComfyUI Manager β†’ search "ComfyUI-mnemic-nodes" β†’ install β†’ restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes
    

    The node itself is pure Python; the pack's other nodes are what pull in transformers, opencv-python and friends via requirements.txt. No models, no API keys, nothing to download.

    Common issues

    Same number every run. Cache, or a fixed seed with unchanged inputs. Nudge something upstream or increment the seed.

    The receiving node won't accept the wire. It needs an INT input, not a FLOAT one. Widgets converted to inputs keep their type - a CFG widget is a float, so feed that from the float node instead.

    Values that make no sense downstream. Integer division is doing it. height // 8 on an odd number is silent rounding, so if you're rolling resolution, stick to multiples of 8 or 64 and save yourself a debugging session.

    Category⚑ MNeMiC Nodes

    Inputs (3)

    NameTypeDefaultDescription
    min_valueINT0-18446744073709550000–18446744073709550000Minimum value for the random integer (inclusive).
    max_valueINT100-18446744073709550000–18446744073709550000Maximum value for the random integer (inclusive).
    seedoptINT-1-1–18446744073709550000Seed for random number generator. Use -1 for random seed (different each time), or set a specific value for reproducibility.

    Outputs (1)

    NameTypeDescription
    random_intINTThe rolled number, inside the range set above.