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

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

Open
simsong opened this issue Sep 4, 2019 · 2 comments
Labels
jira Internal book-keeping label

Comments

@simsong
Copy link

simsong commented Sep 4, 2019

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?

@oleksandr-pavlyk oleksandr-pavlyk added the jira Internal book-keeping label label Jun 25, 2020
@oleksandr-pavlyk
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira Internal book-keeping label
Projects
None yet
Development

No branches or pull requests

2 participants