Use pseudo rng for uuid6 generation

This commit is contained in:
Nuno Campos
2024-09-04 12:07:19 -07:00
parent cf345ef716
commit 4efab93e2f
@@ -3,7 +3,7 @@ https://github.com/oittaa/uuid6-python/blob/main/src/uuid6/__init__.py#L95
Bundled in to avoid install issues with uuid6 package
"""
import secrets
import random
import time
import uuid
from typing import Optional, Tuple
@@ -96,9 +96,9 @@ def uuid6(node: Optional[int] = None, clock_seq: Optional[int] = None) -> UUID:
timestamp = _last_v6_timestamp + 1
_last_v6_timestamp = timestamp
if clock_seq is None:
clock_seq = secrets.randbits(14) # instead of stable storage
clock_seq = random.getrandbits(14) # instead of stable storage
if node is None:
node = secrets.randbits(48)
node = random.getrandbits(48)
time_high_and_time_mid = (timestamp >> 12) & 0xFFFFFFFFFFFF
time_low_and_version = timestamp & 0x0FFF
uuid_int = time_high_and_time_mid << 80