Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

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

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Apr 7, 2012, 10:56 AM

Post #1 of 2 (89 views)
Permalink
[issue12986] Using getrandbits() in uuid.uuid4() is faster and more readable

Serhiy Storchaka <storchaka [at] gmail> added the comment:

> uuids = set()
> for u in [uuid.uuid4() for i in range(1000)]:
> uuids.add(u)

uuids = {uuid.uuid4() for i in range(1000)}

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.

----------
nosy: +storchaka

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue12986>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 7, 2012, 1:06 PM

Post #2 of 2 (87 views)
Permalink
[issue12986] Using getrandbits() in uuid.uuid4() is faster and more readable [In reply to]

Antoine Pitrou <pitrou [at] free> 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>
<http://bugs.python.org/issue12986>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.