mkl_random icon indicating copy to clipboard operation
mkl_random copied to clipboard

it is unclear how to use RDRAND exclusively from numpy.random_intel() from reading the documentation

Open simsong opened this issue 6 years ago • 2 comments

We are using numpy.random_intel with the Intel Anaconda distribution. We need to avoid all uses of Mersenne Twister (which frighteningly is included in random_intel) and rely exclusively on the RDRAND instruction as the randomness source. We then want a random float from the double-tailed geometric distribution.

Unfortunately, the documentation, while including lots of information about distributions, is opaque for how to configure numpy to only use RDRAND as the randomness source. Can you provide me with this information and update the documentation?

simsong avatar Sep 04 '19 13:09 simsong

Create random state instance rs = mkl_random.RandomState(brng='NONDETERM'), and use its methods to sample:

In [22]: import mkl_random

In [23]: rs = mkl_random.RandomState(brng='NONDETERM')

In [24]: rs.randn(20)
Out[24]:
array([-1.59413497, -2.12864449,  1.36852028, -0.62018562, -0.08106982,
        1.66871099,  1.11108356,  0.27281186, -1.55612214,  0.19093763,
       -1.67538538,  1.94252133, -0.35265497, -2.3580535 ,  0.78404063,
        1.10611274, -0.27470842,  0.08642382,  0.36112235,  1.02219966])

In [25]: rs.get_state()[0]
Out[25]: 'NON_DETERMINISTIC'

In [25]: rs.get_state()[0]
Out[25]: 'NON_DETERMINISTIC'

In [26]: rs.seed(123)  # setting seed should not have the effect

In [27]: rs.get_state()[0]
Out[27]: 'NON_DETERMINISTIC'

In [28]: rs.randn(20)
Out[28]:
array([ 0.61510273, -0.03614584, -1.60891747,  0.39283822,  0.81560374,
       -1.01345498,  1.69342887, -1.47101075, -0.12267994, -1.14086205,
        0.95308679,  1.02953698, -0.86667513, -0.53047608, -0.52838244,
       -1.22761643, -0.23550746,  0.78007404, -0.82009213, -0.68805681])

In [29]: rs.seed(123)

In [30]: rs.get_state()[0]
Out[30]: 'NON_DETERMINISTIC'

In [31]: rs.randn(20)  # Out[31] should not be same as Out[28]
Out[31]:
array([-0.64994391, -0.19886474, -0.63953057, -0.19905172,  0.76985611,
       -0.05522171,  0.96441463,  0.41764407,  1.71812938,  0.07714609,
        1.52769265, -1.22215885, -1.08889447, -0.88751625,  1.65156552,
       -0.53803521,  0.24782269, -1.38282226, -0.08232981, -0.76204418])

oleksandr-pavlyk avatar Sep 14 '20 19:09 oleksandr-pavlyk

@simsong The documentation has been updated. Feel free to close if it now provides the required information.

oleksandr-pavlyk avatar Jul 31 '24 13:07 oleksandr-pavlyk