Skip to content

fix use of default_rng seeded with OS noise#54

Open
kelsohmm wants to merge 1 commit intooxwhirl:mainfrom
kelsohmm:main
Open

fix use of default_rng seeded with OS noise#54
kelsohmm wants to merge 1 commit intooxwhirl:mainfrom
kelsohmm:main

Conversation

@kelsohmm
Copy link

@kelsohmm kelsohmm commented Dec 4, 2025

Some functions in the code utilize np.random.default_rng() to create a random number generator, which causes indeterminism in environment behavior and ruins reproducibility.

This function doesn't return the global object of random generator used by numpy, but returns a new Generator object, with its own seed. When the seed= parameter is not used explicitly, "then fresh, unpredictable entropy will be pulled from the OS" and used for the seed of the generator.

In RL environment, its standard to make the environment random number generation fully deterministic based on a global seed number, which usually is set for Python's own random library, numpy's random and any other libraries used with their own random state (like Torch or Tensorflow). Setting the seeds on experiment launch should cause the randomness to be fully deterministic, thus yielding the exact same results when rerunning the same experiment with the same seed on same hardware.

This pull requests replaces the use of np.random.default_rng(seed=None) - seeded with OS noise - with np.random.default_rng(seed=np.random.randint(9999999)) - seeded with a random number, taken from global numpy generator based on the controllable global seed number, making the experiments fully deterministic yet still stochastic.

BEFORE:
before

AFTER:
after

@kelsohmm kelsohmm changed the title fix default_rng system-entropy seeding fix default_rng OS-noise seeding Dec 4, 2025
@kelsohmm kelsohmm changed the title fix default_rng OS-noise seeding fix use of default_rng seeded with OS noise Dec 4, 2025
@kelsohmm kelsohmm marked this pull request as ready for review December 4, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments