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
randint is always even #39295
Comments
The result of (I was trying to find some large prime numbers, and I'm not sure what the cause of the problem is, but Thanks...
|
Logged In: YES The cause is that randint takes a pseudo-random float (C Under Python 2.3, which uses the Mersenne Twister to >>> from random import randint
>>> def f():
... return randint(2**64, 2**65-1)
...
>>> hex(f())
'0x11EDD95B72CEF4000L'
>>> hex(f())
'0x1DD69BF4B39C65000L'
>>> hex(f())
'0x13328DC9C1C733800L'
>>> hex(f())
'0x1E65B47170C057800L'
>>> Under earlier versions of Python, it may be even worse than It takes a fundamentally different kind of algorithm to http://www.faqts.com/knowledge_base/view.phtml/aid/4406 I doubt the implementation of randint() will change, since BTW, given what you're doing, you may want to install one of |
Logged In: YES If the code is not going to be fixed, then the |
Logged In: YES No disagreement here. I'd rather fix the code than the docs, If anyone wants to take this on, I think the latter ("do a right |
Logged In: YES If the range is too large, instead of raising an exception, |
Logged In: YES Ya, something like that indeed. You might enjoy writing the |
Logged In: YES Attached is a first draft of a patch. It works but I don't like the globals for 53 bits per random |
Logged In: YES A cleaner, faster patch is attached along with tests. Unless Tim comes-up with a better idea about obtaining the |
Logged In: YES Here is a patch for Py2.4 that:
A separate patch for Py2.3.3 will be loaded that extends |
Logged In: YES Fixed. See: Thanks for the bug report. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: