Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH/DOC: remove references to np.random.RandomState in favour of np.random.Generator #5342

Closed
tupui opened this issue Apr 21, 2021 · 0 comments · Fixed by #5357
Closed

ENH/DOC: remove references to np.random.RandomState in favour of np.random.Generator #5342

tupui opened this issue Apr 21, 2021 · 0 comments · Fixed by #5357
Labels
⏩ type: Enhancement Improve existing features 🔍 Monitor This ticket's outcome is dependent on an external condition; monitor it.

Comments

@tupui
Copy link
Contributor

tupui commented Apr 21, 2021

Description

Once NumPy minimal version is set to 1.17 #5340, I propose to do a PR to remove from the documentation/code any reference to RandomState and wrong (not best practice) usage of random number generators.

We went through this in SciPy (doc part for now). More on the PR scipy/scipy#13778

Additional context

Since NumPy 1.17, the canonical way to create random numbers is:

import numpy as np
from numpy.random import default_rng
rng = default_rng()

And If a seed is to be used. User should not use a common value such as 0 or 123456. This is to prevent bias (everyone is using the same values) and ensure sufficient entropy for the generator. More details. The good practice (from NumPy's doc) is to generate a seed like this:

from numpy.random import SeedSequence
print(SeedSequence().entropy)

Then you can use the value like

rng = default_rng(my_seed_generated_and_not_common_value)
@alexdesiqueira alexdesiqueira added the ⏩ type: Enhancement Improve existing features label Apr 26, 2021
@sciunto sciunto added the 🔍 Monitor This ticket's outcome is dependent on an external condition; monitor it. label Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏩ type: Enhancement Improve existing features 🔍 Monitor This ticket's outcome is dependent on an external condition; monitor it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants