[issue13396] new method random.getrandbytes()

Amaury Forgeot d'Arc report at bugs.python.org
Sun Nov 13 22:14:58 CET 2011


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

./python -m timeit -s "from random import getrandbits" "getrandbits(8000000).to_bytes(1000000, 'little')"
10 loops, best of 3: 25 msec per loop

./python -m timeit -s "from random import getrandbytes" "getrandbytes(1000000)"
100 loops, best of 3: 9.66 msec per loop

For the Mersenne Twister, getrandbytes() is ~2.5 times faster (A length of 1000 gives exactly the same ratio)
When applied to the SytemRandom object, the difference is less impressive (probably because os.urandom is slow) but getrandbytes is still 20ms faster.

Updated patch to add getrandbytes at the module level, and to SystemRandom.

----------
Added file: http://bugs.python.org/file23682/getrandbytes.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13396>
_______________________________________


More information about the Python-bugs-list mailing list