Table of Contents

Class Seeding

Namespace
Gym.Utils
Assembly
Gym.dll

The one way Gym.NET's envs and spaces create their random number generators. Every generator is NumPy's Generator(PCG64(SeedSequence(seed))), which NumSharp implements bit for bit, so a Gym.NET space or env seeded with s draws exactly what Gymnasium's draws for seed s, provided it makes the same calls.

public static class Seeding
Inheritance
Seeding
Inherited Members

Remarks

A generator is owned by whoever stores it and is not synchronized: give every env and space its own instance, as Gymnasium gives each its own np_random. It replaces the former LegacySeeding, which built NumPy's legacy RandomState (MT19937), a different generator family that Gymnasium no longer uses. Reference: gymnasium/utils/seeding.py.

Methods

NpRandom(BigInteger?)

A new generator, and the seed it was built from. Seeded with a value, it is reproducible; unseeded (null), it draws fresh OS entropy, as Gymnasium does when a seed is not given, and the returned seed is then the only way to reproduce it.

public static (Generator Rng, BigInteger Seed) NpRandom(BigInteger? seed = null)

Parameters

seed BigInteger?

Any non-negative integer, of any size, like Gymnasium's Python-int seeds (every C# integer type converts implicitly); null seeds from OS entropy.

Returns

(Generator Rng, BigInteger Seed)

The generator, and seed_seq.entropy: seed itself, or for an unseeded generator the 128-bit entropy it was drawn from, which is why it is a BigInteger. Passing that value back rebuilds the same generator, here and in Gymnasium: since NumSharp 0.80.0 an unseeded sequence builds its pool from that very integer, as NumPy does, so even an entropy whose top 32-bit word is zero (1 in 2^32) round-trips.

Remarks

The steps are Gymnasium's np_random: validate, build SeedSequence(seed), report seed_seq.entropy, and wrap PCG64(seed_seq) in a Generator. Gymnasium's other check, "Seed must be a python integer", cannot fail for a typed integer. Reference: gymnasium/utils/seeding.py.

Exceptions

Error

Thrown when seed is negative, with Gymnasium's message "Seed must be greater or equal to zero, actual value: …".