[issue13396] new method random.getrandbytes()

Antoine Pitrou report at bugs.python.org
Sun Nov 13 21:41:35 CET 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

> The problem is that we need an API that will accommodate other random
> number generators and not be specific to the MersenneTwister.  Right
> now, the starting point for everything in the random module is an
> underlying generator supplying a random() method returning a float and
> an optional getrandombits() method which returns an int (possibly a
> long int).

Well, you can provide a default getrandombytes() which calls into
getrandombits(), and specialize it in the case genrand_int32() exists.

>   The latter is easily convertible to bytes with to_bytes() which uses
> a fast O(n) algorithm.

Well, O(n) doesn't necessarily equate fast. Can Amaury post benchmark
numbers of getrandbits().to_bytes() vs getrandbytes()?

----------

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


More information about the Python-bugs-list mailing list