This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Lib/random.py: use more efficient code to convert bytes to integer
Type: performance Stage:
Components: Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, vstinner
Priority: normal Keywords: easy

Created on 2014-04-30 10:07 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg217595 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-04-30 10:07
In Lib/random.py, I see lines like that:

   long(_hexlify(_urandom(32)), 16)

I guess that something more efficient can be fonud to convert a bytes string to an integer.

bytes.from_bytes() maybe?
msg217599 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-04-30 10:34
Do you mean int.from_bytes?

It's already changed in Python 3.5: int.from_bytes(_urandom(32), 'big').
msg217663 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-04-30 22:33
Oops, I didn't read the right version of the code.
History
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65593
2014-04-30 22:33:31vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg217663
2014-04-30 10:34:36Claudiu.Popasetnosy: + Claudiu.Popa
messages: + msg217599
2014-04-30 10:07:47vstinnercreate