Description
np.random.RandomState is not a good choice for random number generation going forward:
RandomState is effectively frozen and will only receive updates that are required by changes in the the internals of Numpy. More substantial changes, including algorithmic improvements, are reserved for Generator.
I don't understand all the details, but the TL;DR I've gathered from monitoring some SciPy discussions is that it's not as good as the new default_rng
/ Generator
-based way of making random numbers and it should be replaced in people's code.
In the long term I think we want to switch random_state=0
to use default_rng(random_state)
instead of RandomState(random_state)
internally. I propose:
- Have a
mne.set_rng_backend(backend)
that can be'RandomState'
or'Generator'
, maybe with ause_rng_backend
context manager. The context manager is maybe overkill, but I do think it might help people transition code from old to new, and it's only a few lines for us. - If this has not been called by the user yet, if they do
random_state=<int>
they will see a DeprecationWarning stating that the default is'RandomState'
in 0.23 but will change to'Generator'
in 0.24 (or maybe this is a good case for making it 0.25 to give people more time to change over), and we will callset_rng_backend('RandomState')
. - In 0.24 (or 0.25) we no longer emit this warning and just use
'Generator'
.
I think this is a workable solution for modernizing our random_state
params.