ComfyUI Node

Pt Rand

Pt Rand rolls uniform noise in the shape you ask for

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

    PtRand is torch.rand() wearing a node costume: it fills a tensor of your chosen shape with random values drawn from a uniform distribution between 0 and 1. It's the pack's go-to for fabricating random input on the fly - synthetic test data, random noise to inject into a workflow, or a quick sanity check that your graph handles an arbitrary tensor without caring what's inside.

    How it works

    Like its sibling Pt Ones, the shape comes in as text and the node parses it: [2,3,96,32] gives you a 4D tensor of that size. Two inputs:

    • size - a bracketed list like [2,3,96,32], any number of dims. Same strict text parsing as PtOnes - it must evaluate as a Python list.
    • data_type - the float dtype, restricted to float32 (default), float16, bfloat16, or float64. Unlike PtOnes, no integer or bool options - which makes sense, since values are uniform in [0, 1) and ints wouldn't survive.

    Output is a single TENSOR in the pack's format, ready for any Pt* node.

    The thing that trips people up

    This node re-rolls the dice every time it executes - the source marks IS_CHANGED as NaN, which tells ComfyUI the output is never "the same as last time," so a rerun (or any change upstream) produces fresh random values. That's usually what you want for noise, but if you're trying to reproduce a run exactly, this node is your reproducibility enemy: it has no seed input. For deterministic experiments, either build your random tensor once and cache it in a variable, or rely on the pack's Pt Randn/distribution nodes if you need seed control. If your loss curves or comparisons keep shifting between runs and you have a PtRand in the graph, this is why.

    When to reach for it

    Synthetic test data is the star use: want to check that a model node accepts a (batch, seq, features) tensor without building a real dataset? Feed it a Pt Rand tensor of the right shape and run. It's also handy for injecting random noise into inputs for augmentation experiments. Just keep the reproducibility caveat in mind and it's a genuinely useful little utility.

    Installing it

    Part of ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch pack, a spin-off of ComfyUI-Data-Analysis). ComfyUI Manager → search "ComfyUI-Pt-Wrapper", or:

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

    Restart after; first boot is slow while pandas, scikit-learn, transformers, sentencepiece, peft and friends install. No model downloads needed.

    CategoryData Analysis

    Inputs (2)

    NameTypeDefaultDescription
    sizeSTRING
    data_typeCOMBO4 options: float32, float16, bfloat16, float64

    Outputs (1)

    NameTypeDescription
    TENSORTENSOR