latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.random API
Functions 8
default_generator
functionFull reference ↗- tensorplay.random.default_generator() tensorplay._C.Generator
fork_rng
functionFull reference ↗- tensorplay.random.fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices')[source]
Forks the RNG state: code inside the context gets a pristine RNG.
Saves the CPU RNG state and the RNG state of every CUDA device listed in
deviceson entry and restores them on exit, so random operations inside the block do not advance the outer streams.devices=[]forks only the CPU generator.
get_rng_state
functionFull reference ↗- tensorplay.random.get_rng_state() tensorplay::Tensor
initial_seed
functionFull reference ↗- tensorplay.random.initial_seed() int
manual_seed
functionFull reference ↗- tensorplay.random.manual_seed(seed: SupportsInt | SupportsIndex) None
seed
functionFull reference ↗- tensorplay.random.seed() int
set_rng_state
functionFull reference ↗- tensorplay.random.set_rng_state(new_state: tensorplay::Tensor) None
thread_safe_generator
functionFull reference ↗- tensorplay.random.thread_safe_generator()[source]
Returns a thread-safe random number generator for use in DataLoader workers.
This function provides a convenient way for transforms and user code to use thread-safe random number generation without manually checking worker context.
When called in a DataLoader thread worker, returns the worker’s thread-local
tensorplay.Generator. When called in the main process or process workers, returnsNone(which causes operations to use the default global RNG).Example
>>> from tensorplay.random import thread_safe_generator >>> generator = thread_safe_generator() >>> tensorplay.randint(0, 10, (5,), generator=generator)
Help improve this page
Found an error, an unclear step, or a missing example?

