Skip to content

Overview

rng

A sub-package to handle random number generators.

Classes

RNGManager

RNGManager(seed: int | None = None)

Manager for random number generation with state persistence.

Initialize the RNG manager.

Parameters:

Name Type Description Default
seed int | None

Random seed. If None, draw a random integer between [0, 2**63).

None
Attributes
requested_seed property
requested_seed: int | None

Get the seed the caller asked for.

Returns:

Type Description
int | None

The requested seed, or None if the caller left the choice open.

resolved_seed property
resolved_seed: int

Get the seed this generator was actually initialized with.

This is the value to record when describing a run: it equals :attr:requested_seed when one was given, and the drawn value when it was not.

Returns:

Type Description
int

The seed in use.

key property writable
key: Array

Get the random number generator key.

Returns:

Type Description
Array

JAX random key.

key_data property writable
key_data: Array

Get the key data.

The function can be used to retrieve the key data for storing in disk.

Returns:

Type Description
Array

Key data.

new_key property
new_key: Array

Get a new key.

Returns:

Type Description
Array

A new key.

Methods:
save_key
save_key(path: str | Path) -> None

Save RNG key to file.

Parameters:

Name Type Description Default
path str | Path

Path to save the key file.

required
load_key
load_key(path: str | Path) -> None

Load RNG key from file.

Parameters:

Name Type Description Default
path str | Path

Path to load the key file.

required