Nodes/Bjornulf_custom_nodes/๐ŸŽฒ Random Integer
ComfyUI Node

๐ŸŽฒ Random Integer

A random whole number, plus a text copy of it

By justUmenยทCreated 2 years agoยทUpdated about a year agoยท 545
๐ŸŽฒ Random Integer
    • INT
    • STRING
    โ—„min_value1โ–บ
    โ—„max_value10โ–บ
    โ—„seed0โ–บ

    Sometimes you just need a random whole number between two bounds - a step count to sweep, a batch size, an index into a list, a value to jitter some parameter shot to shot. Random Integer does exactly that: pick a min and a max, and it hands you a random INT in that range. Small node, does one thing, no surprises.

    The one nice extra: it also gives you a string version of the same number. That sounds trivial until you're trying to inject the value into a prompt or a filename, where you need text, not an int. Having both come out of one node saves you a converter.

    How it works

    On each run it draws a random integer between min_value and max_value (inclusive of the range you set) and outputs it two ways - as an INT for wiring into numeric widgets, and as a STRING for anywhere text is expected. Randomness is driven by the seed, which behaves like every other seed in ComfyUI: set its control to "randomize" and you get a fresh number every queue; fix it and you get the same number every time, which is exactly what you want when you're trying to reproduce a result.

    The inputs and outputs that matter

    • min_value (INT, default 1) - the low bound.
    • max_value (INT, default 10) - the high bound.
    • seed (INT) - controls the draw. Randomize it for variety, pin it for reproducibility. This is the one people forget: if your "random" number never changes, your seed control is set to fixed.

    Two outputs:

    • INT - the number, for numeric inputs (steps, batch counts, indices).
    • STRING - the same number as text, for prompts, filenames, or labels.

    How to install it

    ComfyUI Manager: search Bjornulf_custom_nodes, install, restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/justUmen/Bjornulf_custom_nodes
    pip install -r Bjornulf_custom_nodes/requirements.txt
    

    then restart. No dependency of note - it's arithmetic, so it always loads.

    Common issues & troubleshooting

    The number never changes between runs. Your seed control is on "fixed." Set it to "randomize" (the control-after-generate dropdown under the seed) and you'll get a new value each queue. This is the single most common confusion with every seeded node, not just this one.

    I want a new number within one run / per loop iteration. A single node evaluates once per graph execution, so it produces one number per run, not one per loop step. If you need per-iteration randomness, that's a different pattern - drive the randomness from inside the loop, or reach for one of the pack's loop-oriented nodes.

    I need a decimal, not a whole number. Wrong node - use the pack's Random Float, which does the same thing for floating-point values (and likewise gives you a text copy).

    The range feels off by one. Set min_value and max_value to the exact inclusive bounds you want. If you need "0 to 9," say 0 and 9, not 0 and 10.

    Feeding the INT into a widget didn't take. Some KSampler widgets have to be converted to inputs first - right-click the target node and convert the widget (e.g. steps) to an input before you can wire a number into it.

    CategoryBjornulf

    Inputs (3)

    NameTypeDefaultDescription
    min_valueINT1โ€”
    max_valueINT10โ€”
    seedINT00โ€“4294967294โ€”

    Outputs (2)

    NameTypeDescription
    INTINTโ€”
    STRINGSTRINGโ€”