torch.func._random.bits#
- torch.func._random.bits(key, *shape, dtype=None)[source]#
Generate raw random bits from a PRNG key.
Equivalent to
randint()over the full range ofdtype. That range is a power of two, so unlike a bounded draw this is exactly uniform. Signed dtypes receive negative values as well.Dtypes narrower than 32 bits take the low bits of a full 32-bit sample, so
bits(key, shape, dtype=torch.int8)matchesbits(key, shape, dtype=torch.int32).to(torch.int8).Supports batched keys: if
keyhas shape(*batch, K), the leading dimensions ofshapemust be broadcastable with*batchand each key independently generates its slice of the output.- Parameters:
- Returns:
A tensor of the given shape filled with raw random bits.
- Return type:
Example:
>>> key = torch.func._random.key(42, device="cuda") >>> torch.func._random.bits(key, (1000,), dtype=torch.uint64)