How to seed scipy.stats.norm.rvs and have it to use the PCG64 BitGenerator?

Viewed 656

This answer provided a brief introduction on scipy.stats.norm.rv.

To seed this function, I did the following and got the following results.

>>> norm.rvs(size=10, random_state=12345)
array([-0.20470766,  0.47894334, -0.51943872, -0.5557303 ,  1.96578057,
        1.39340583,  0.09290788,  0.28174615,  0.76902257,  1.24643474]

Questions:

  1. For NumPy v1.19, is this function using NumPy's SeedSequence or the legacy seeding algorithm to seed the generator? If the former, how do I pass the child_seeds of the SeedSequence to it?

  2. How do I get scipy.stats.norm.rv to use numpy.random.default_rng() or the BitGenerator (PCG64) instead of the MT19937 BitGenerator. According to NumPy's documentation, I understand that RandomState refers to NumPy's Legacy Random Generation which is the MT19937 BitGenerator. I did the following and got an exception:

    >>> from scipy.stats import norm
    >>> from numpy.random import default_rng
    >>> rg = default_rng( 12345 )
    >>> norm.rvs(size=10, random_state=rg)
    ValueError: Generator(PCG64) at 0x7F19E528D228 cannot be used to seed a numpy.random.RandomState instance
    
0 Answers
Related