Skip to content

Commit 69ce4ca

Browse files
authored
Update uuid.py
1 parent f00512d commit 69ce4ca

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

Lib/uuid.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ def _random_getnode():
666666
# counting from 1 being the least significant bit, or 1<<40.
667667
#
668668
# See https://en.wikipedia.org/w/index.php?title=MAC_address&oldid=1128764812#Universal_vs._local_(U/L_bit)
669-
import random
670-
return random.getrandbits(48) | (1 << 40)
669+
import secrets
670+
return secrets.randbits(48) | (1 << 40)
671671

672672

673673
# _OS_GETTERS, when known, are targeted for a specific OS or platform.
@@ -746,8 +746,8 @@ def uuid1(node=None, clock_seq=None):
746746
timestamp = _last_timestamp + 1
747747
_last_timestamp = timestamp
748748
if clock_seq is None:
749-
import random
750-
clock_seq = random.getrandbits(14) # instead of stable storage
749+
import secrets
750+
clock_seq = secrets.randbits(14) # instead of stable storage
751751
time_low = timestamp & 0xffffffff
752752
time_mid = (timestamp >> 32) & 0xffff
753753
time_hi_version = (timestamp >> 48) & 0x0fff
@@ -809,8 +809,8 @@ def uuid6(node=None, clock_seq=None):
809809
timestamp = _last_timestamp_v6 + 1
810810
_last_timestamp_v6 = timestamp
811811
if clock_seq is None:
812-
import random
813-
clock_seq = random.getrandbits(14) # instead of stable storage
812+
import secrets
813+
clock_seq = secrets.randbits(14) # instead of stable storage
814814
time_hi_and_mid = (timestamp >> 12) & 0xffff_ffff_ffff
815815
time_lo = timestamp & 0x0fff # keep 12 bits and clear version bits
816816
clock_s = clock_seq & 0x3fff # keep 14 bits and clear variant bits
@@ -913,14 +913,14 @@ def uuid8(a=None, b=None, c=None):
913913
When a value is not specified, a pseudo-random value is generated.
914914
"""
915915
if a is None:
916-
import random
917-
a = random.getrandbits(48)
916+
import secrets
917+
a = secrets.randbits(48)
918918
if b is None:
919-
import random
920-
b = random.getrandbits(12)
919+
import secrets
920+
b = secrets.randbits(48)
921921
if c is None:
922-
import random
923-
c = random.getrandbits(62)
922+
import secrets
923+
c = secrets.randbits(48)
924924
int_uuid_8 = (a & 0xffff_ffff_ffff) << 80
925925
int_uuid_8 |= (b & 0xfff) << 64
926926
int_uuid_8 |= c & 0x3fff_ffff_ffff_ffff

0 commit comments

Comments
 (0)