10000 BUG: Change in random number sequence when np.random.RandomState.choice is used · Issue #28078 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Change in random number sequence when np.random.RandomState.choice is used #28078

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

Closed
SelinBayramoglu opened this issue Dec 30, 2024 · 1 comment
Labels
33 - Question Question about NumPy usage or development

Comments

@SelinBayramoglu
Copy link
SelinBayramoglu commented Dec 30, 2024

Describe the issue:

I create a random number generator (rng) with a seed to get a reproducible list of random numbers. The first two numbers in this list are num1 and num2. Before generating these numbers, I use the choice() to pick a value in a list. When I generate two numbers again, I get num3 and num4. I expected num2 and num3 to be the same, since they are generated when rng is called twice. However, I get different numbers.

Reproduce the code example:

import numpy as np

rng = np.random.RandomState(0)

num1 = rng.rand()
num2 = rng.rand()

print(num1, num2)
# 0.5488135039273248 0.7151893663724195

alist = range(1,101)

rng = np.random.RandomState(0)

a = rng.choice(alist)
num3 = rng.rand()
num4 = rng.rand()

print(num3, num4)
# 0.5928446182250183 0.8442657485810173

Error message:

No response

Python and NumPy Versions:

Numpy version: 1.26.2
Python version: 3.9.18 (main, Sep 11 2023, 13:21:18)
[GCC 11.2.0]

Runtime Environment:

[{'numpy_version': '1.26.2',
'python': '3.9.18 (main, Sep 11 2023, 13:21:18) \n[GCC 11.2.0]',
'uname': uname_result(system='Linux', node='atl1-1-02-003-16-1.pace.gatech.edu', release='5.14.0-427.26.1.el9_4.x86_64', version='#1 SMP PREEMPT_DYNAMIC Fri Jul 5 11:34:54 EDT 2024', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX'],
'not_found': ['AVX512_KNL',
'AVX512_KNM',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'SkylakeX',
'filepath': '/storage/home/hcoda1/0/sbayramoglu3/.local/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so',
'internal_api': 'openblas',
'num_threads': 4,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.23.dev'}]

Context for the issue:

No response

@rkern rkern added 33 - Question Question about NumPy usage or development and removed 00 - Bug labels Dec 30, 2024
@rkern
Copy link
Member
rkern commented Dec 30, 2024

This is expected. choice() consumes more iterations of the core PRNG that rand() does (depending on the size of the input).

@rkern rkern closed this as n 4EEF ot planned Won't fix, can't repro, duplicate, stale Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
33 - Question Question about NumPy usage or development
Projects
None yet
Development

No branches or pull requests

2 participants
0