[issue45556] uuid.uuid4() fast optimization

Christian Heimes report at bugs.python.org
Thu Oct 21 14:29:24 EDT 2021


Christian Heimes <lists at cheimes.de> added the comment:

We use os.urandom() because it is backed by a cryptographicly secure random number generator. The random module uses a non-secure RNG. While RFC 4122 does not mandate a CSRPNG, application often rely on unpredictable UUIDs. Correctness and security is more important here than performance.

If you need a faster uuid4 implementation, then you can role your own with a couple of lines of code:

import random
from uuid import UUID

def uuid4_fast():
    return UUID(int=random.getrandbits(128), version=4)

----------
nosy: +christian.heimes
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45556>
_______________________________________


More information about the Python-bugs-list mailing list