sequince.utils.random

sequince.utils.random#

Attributes#

Functions#

resolve_rng([rng, backend, xp])

Return an ORNG generator for the supplied RNG-like value.

Module Contents#

type sequince.utils.random.RNGLike = RandomGenerator | np.random.Generator | int | None#
sequince.utils.random.resolve_rng(rng=None, *, backend=None, xp=None)[source]#

Return an ORNG generator for the supplied RNG-like value.

Parameters:
  • rng (RNGLike) – An RNG-like value, which can be an ORNG RandomGenerator, a NumPy Generator, an integer seed, or None (for a default generator).

  • backend (str | None) – The backend to use for the ORNG RandomGenerator if rng is None or an integer seed. Ignored if rng is an ORNG RandomGenerator or a NumPy Generator.

  • xp (Any | None) – An array API namespace to use for the ORNG RandomGenerator if rng is None or an integer seed. Ignored if rng is an ORNG RandomGenerator or a NumPy Generator.

Returns:

An ORNG RandomGenerator instance corresponding to the provided rng value, using the specified backend or xp if necessary.

Return type:

RandomGenerator

Raises:
  • TypeError – If rng is not an ORNG RandomGenerator, a NumPy Generator, an integer seed, or None.

  • ValueError – If both backend and xp are specified.