Skip to content

Commit b55adc4

Browse files
committed
explain rationale of randomized clock sequence
1 parent 2de0a05 commit b55adc4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/uuid.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,15 @@ def uuid6(node=None, clock_seq=None):
751751
timestamp = _last_timestamp_v6 + 1
752752
_last_timestamp_v6 = timestamp
753753
if clock_seq is None:
754+
# If the caller does not specify a clock sequence, we may assume that
755+
# sequentiality within the same 60-bit timestamp is less important
756+
# than unpredictability. In particular, by using a randomized clock
757+
# sequence, we indirectly slow down the next call, thereby allowing
758+
# the next 60-bit timestamp to be distinct.
759+
#
760+
# Stated otherwise, it is unlikely that two UUIDs are generated within
761+
# the same 100-ns interval since constructing a UUID object takes more
762+
# than 100 ns.
754763
import random
755764
clock_seq = random.getrandbits(14) # instead of stable storage
756765
time_hi_and_mid = (timestamp >> 12) & 0xffff_ffff_ffff

0 commit comments

Comments
 (0)