Nodes/ComfyDL/Random Tensor
ComfyUI Node

Random Tensor

ComfyDL's noise generator for testing, init, and inputs

By Cynthia-lxx·Created 2 months ago·Updated 3 days ago· 6
Random Tensor
    • tensor
    shape4,4
    distnormal
    mean0.0
    std1.0
    low0.0
    high1.0
    seed-1

    Sometimes you just need some random numbers. CdlRandomTensor generates a tensor of any shape you ask for, drawn from one of three distributions, with an optional seed. It sounds trivial - and it kind of is - but in a pack built for doing deep learning in a node graph, random tensors are how you feed a GAN's noise vector, initialize a synthetic-data experiment, or just get something into a graph you're still building.

    This is ComfyDL in its purest form: a thin, honest wrapper around a torch call (torch.randn, torch.rand, torch.randint), wrapped so you can drive it from the graph instead of a Python prompt. Nothing fancy, but it's the node every experimental workflow ends up needing.

    The inputs

    • shape - a comma-separated string, e.g. "4,4" or "2,3,4". The only required thing that isn't a distribution parameter.
    • dist - normal, uniform, or randint.
    • mean / std - the normal distribution's parameters (defaults 0.0 / 1.0, i.e. standard normal).
    • low / high - bounds for uniform and randint. Note both are from [low, high) - high is exclusive. For randint, values are integers.
    • seed - the quiet superpower. Default -1 = random every run; set it to 0 or above and the RNG is fixed, giving you the same tensor every time you execute. That's how you make a test reproducible.

    Output: tensor, a cdlTensor of your requested shape.

    The seed matters more than you think

    ComfyUI caches aggressively, and a random node that produces different values each run can subtly poison caching around it. When you're debugging whether a change upstream actually changed the result, lock the seed to -1... no, the other way: lock it to a fixed value. A fixed seed turns "did my edit change the output?" from a gamble into a test. Reserve -1 for when you genuinely want fresh randomness per run - a GAN's noise input, a Monte Carlo experiment - and even then, pin it to reproduce a specific result you liked.

    Installing ComfyDL

    Standard for this pack - light:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Cynthia-lxx/ComfyDL
    cd ComfyDL && pip install -r requirements.txt
    

    Restart ComfyUI; it's under ComfyDL → Tensor Basic. ComfyUI Manager users search "ComfyDL". Only dependency is matplotlib; no downloads.

    Gotchas

    Empty shape string raises a ValueError - ComfyUI will show it as a node error, so keep the default "4,4" if you're unsure. And the output is a cdlTensor, which means it only connects to other ComfyDL nodes. Don't try to feed it into a stock ComfyUI noise node or sampler - the type won't match, and that's by design; this pack is a self-contained sandbox for building neural nets, not for diffusion sampling.

    One more thing worth knowing: torch.manual_seed is global, not per-node. If you've got two Random Tensor nodes with the same seed in one graph, they'll be correlated (identical sequences) rather than independent. Give them different seeds if you want them to behave like separate draws.

    Categoryd2l/Tensor Basic

    Inputs (7)

    NameTypeDefaultDescription
    shapeSTRING4,4
    distCOMBOnormal3 options: normal, uniform, randint
    meanFLOAT0.0-1000000–1000000
    stdFLOAT1.00–1000000
    lowFLOAT0.0-1000000–1000000
    highFLOAT1.0-1000000–1000000
    seedINT-1-1–2147483647

    Outputs (1)

    NameTypeDescription
    tensorTENSOR