[issue12986] Using getrandbits() in uuid.uuid4() is faster and more readable

Antoine Pitrou report at bugs.python.org
Sat Apr 7 22:06:38 CEST 2012


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

> However, I'm not sure of the legitimacy of replacement suitable for
> cryptographic use `os.urandom` on fast pseudo-random
> `random.getrandbits`. Especially for applications that need to generate 
> a lot of uuids.

Agreed. urandom() is supposed to incorporate "real" random, while getrandbits() uses a PRNG.
Also, as the OP shows, it's easy to inject your own random source:

  >>> grb = "uuid.UUID(int=random.getrandbits(128), version=4)"

if you really need the speed.

----------
nosy: +pitrou
stage:  -> patch review
versions: +Python 3.3 -Python 3.2

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


More information about the Python-bugs-list mailing list