Rate this Page
★ ★ ★ ★ ★

torch.func._random#

Created On: Nov 16, 2026 | Last Updated On: Nov 16, 2026

Warning

These APIs are a prototype and may change or be removed without notice. The module is private and not covered by PyTorch’s backward compatibility policy. Read more about feature classification at: https://pytorch.org/blog/pytorch-feature-classification-changes/#prototype

torch.func._random provides JAX-style stateless PRNG APIs: randomness is a pure function of an explicit key tensor rather than of global generator state. The module is not imported by import torch; import it explicitly with import torch.func._random before use.

These APIs do not yet support torch.func.vmap(). To generate a batch of independent samples, pass a batch of keys with shape (*batch, K) (e.g. from split()) instead.

key

Create a PRNG key from a seed.

split

Split a PRNG key into num new independent keys.

fold_in

Deterministically derive a new key by folding in an integer value.

uniform

Generate uniformly distributed random values from a PRNG key.

uniform_

Fill result in-place with uniform random values from a PRNG key.

normal

Generate normally distributed random values from a PRNG key.

normal_

Fill result in-place with normal random values from a PRNG key.

randint

Generate uniform random integers in [low, high) from a PRNG key.

randint_

Fill result in-place with uniform random integers in [low, high).

bits

Generate raw random bits from a PRNG key.

bits_

Fill result in-place with raw random bits from a PRNG key.