Skip to content

Conversation

@NickCrews
Copy link

@NickCrews NickCrews commented Jan 15, 2026

Description

Fixes pytest-dev/pytest-randomly#689 and #960

np.random.seed() only works with seeds in range 0 to (2**32)-1. However, in our util function, we accept an arbitrary python int, which could be larger than this. Now, we modulo the given seed to the acceptable range for numpy.

torch says it needs a seed in the range [-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff], so I fixed that as well.

The other backends, such as cupy and cuda, mention no range limits in their docs, so I will leave them as-is for now.

I ran into this when using this library with pytest-randomly, which calls fix_random_seed(an int possibly larger than 2**32-1) during test initialization using the 'pytest_randomly.random_seeder' entry point.

Types of change

Fix

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

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.

Reseed errors out with numpy legacy seeding

1 participant