@@ -22,6 +22,7 @@ from ._bounded_integers cimport (_rand_bool, _rand_int32, _rand_int64,
22
22
_rand_int16 , _rand_int8 , _rand_uint64 , _rand_uint32 , _rand_uint16 ,
23
23
_rand_uint8 , _gen_mask )
24
24
from ._pcg64 import PCG64
25
+ from ._mt19937 import MT19937
25
26
from numpy .random cimport bitgen_t
26
27
from ._common cimport (POISSON_LAM_MAX , CONS_POSITIVE , CONS_NONE ,
27
28
CONS_NON_NEGATIVE , CONS_BOUNDED_0_1 , CONS_BOUNDED_GT_0_1 ,
@@ -4990,14 +4991,15 @@ def default_rng(seed=None):
4990
4991
4991
4992
Parameters
4992
4993
----------
4993
- seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional
4994
+ seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator, RandomState }, optional
4994
4995
A seed to initialize the `BitGenerator`. If None, then fresh,
4995
4996
unpredictable entropy will be pulled from the OS. If an ``int`` or
4996
4997
``array_like[ints]`` is passed, then all values must be non-negative and will be
4997
4998
passed to `SeedSequence` to derive the initial `BitGenerator` state. One may also
4998
4999
pass in a `SeedSequence` instance.
4999
5000
Additionally, when passed a `BitGenerator`, it will be wrapped by
5000
5001
`Generator`. If passed a `Generator`, it will be returned unaltered.
5002
+ When passed a legacy `RandomState` instance it will be coerced to a `Generator`.
5001
5003
5002
5004
Returns
5003
5005
-------
@@ -5070,6 +5072,14 @@ def default_rng(seed=None):
5070
5072
elif isinstance (seed , Generator ):
5071
5073
# Pass through a Generator.
5072
5074
return seed
5075
+ elif isinstance (seed , np .random .RandomState ):
5076
+ rs_state = seed .get_state (legacy = False )
5077
+ klass = getattr (np .random , rs_state ['bit_generator' ])
5078
+ bg = klass ()
5079
+ bg .state = rs_state
5080
+ gen = np .random .Generator (bg )
5081
+ return gen
5082
+
5073
5083
# Otherwise we need to instantiate a new BitGenerator and Generator as
5074
5084
# normal.
5075
5085
return Generator (PCG64 (seed ))
0 commit comments