ComfyUI Node

Pt Rand Int

Random integer tensors without writing a line of Python

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Rand Int
    • TENSOR
    min_value0
    max_value1
    size
    data_type

    Pt Rand Int is the node you reach for when you need a tensor full of random integers in ComfyUI but don't want to leave the graph to do it. It's part of ComfyUI-Pt-Wrapper, a pack that drags raw PyTorch into ComfyUI so you can build and train models without coding. This node is the "make some data" step - a placeholder input for a model, noise for an experiment, index values to test a scatter or gather against. If you've ever built a workflow and thought "I just need a quick tensor of random numbers to feed this," this is that node.

    What it actually does

    Under the hood it's a thin wrapper around torch.randint(min, max, size). You type a shape as a Python list, give it a low and high bound, and out comes a tensor of random integers drawn uniformly from [min_value, max_value) - the max is exclusive, so min_value=0, max_value=10 gives you 0 through 9, never 10. It then spits out a TENSOR you can wire into any other TENSOR input in the pack.

    The inputs that matter:

    • size - a multiline text field where you type the shape as a list, e.g. [2,3,96,32] for a 4D tensor of batch 2, channels 3, height 96, width 32.
    • min_value and max_value - the inclusive low and exclusive high bounds. Max has to be bigger than min or the node throws a ValueError.
    • data_type - pick from uint8, int8, int16, int32, int64. Default ints in PyTorch are int64, so if you're feeding something picky about dtypes (like an embedding table that expects long), the choices are there.

    How to install it

    Pt Rand Int ships inside the ComfyUI-Pt-Wrapper pack, so installing once gets you all ~200 of its nodes. Easiest path is ComfyUI Manager: search ComfyUI-Pt-Wrapper in the Custom Nodes Manager and hit Install, then restart ComfyUI. Or do it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
    

    Then restart ComfyUI. One heads-up before you click: the pack's requirements.txt drags in a serious stack - transformers, datasets, accelerate, peft, gensim, sentencepiece, scikit-learn, scipy, pandas, seaborn, matplotlib. First launch is slow and there's real conflict potential if another node you have pins a different transformers version. It's a training-oriented pack; installing it just for random tensors is a lot of dependency to swallow.

    Gotchas

    The shape field is parsed with Python's ast.literal_eval, which means it has to be valid Python list syntax - [2,3,96,32], not 2,3,96,32 or 2 3 96 32. That trips up more people than anything else here. Missing brackets is the #1 way this node errors on you.

    The bigger gotcha: there's no seed input. The node seeds its own RNG from the wall clock at init and its IS_CHANGED returns NaN, so it regenerates fresh random values on every single run of the graph. That's what you want for noise, and exactly what you don't want if you're trying to reproduce an experiment. There's a set_seed helper elsewhere in the pack, but this node doesn't expose it. If you need reproducible randomness, this isn't the node - you'd want the seed-controlled creation nodes elsewhere in the pack instead.

    CategoryData Analysis

    Inputs (4)

    NameTypeDefaultDescription
    min_valueINT0-2147483648–2147483648
    max_valueINT1-2147483648–2147483648
    sizeSTRING
    data_typeCOMBO5 options: uint8, int8, int16, int32, int64

    Outputs (1)

    NameTypeDescription
    TENSORTENSOR