Skip to content

Commit 7f84d30

Browse files
authored
remove _getrandbits (#14)
1 parent f2f850f commit 7f84d30

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

src/uuid6/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ def unixts(self) -> int:
5454
return self.time_low << 4 | self.time_mid >> 12
5555

5656

57-
def _getrandbits(k: int) -> int:
58-
return secrets.randbits(k)
59-
60-
6157
def _subsec_decode(value: int) -> int:
6258
return math.ceil(value * 10 ** 9 / 2 ** 30)
6359

@@ -85,8 +81,8 @@ def uuid6(clock_seq: int = None) -> UUID:
8581
timestamp = _last_v6_timestamp + 1
8682
_last_v6_timestamp = timestamp
8783
if clock_seq is None:
88-
clock_seq = _getrandbits(14) # instead of stable storage
89-
node = _getrandbits(48)
84+
clock_seq = secrets.randbits(14) # instead of stable storage
85+
node = secrets.randbits(48)
9086
time_high_and_time_mid = (timestamp >> 12) & 0xFFFFFFFFFFFF
9187
time_low_and_version = timestamp & 0x0FFF
9288
uuid_int = time_high_and_time_mid << 80
@@ -116,7 +112,7 @@ def uuid7() -> UUID:
116112
subsec_a = subsec >> 18
117113
subsec_b = (subsec >> 6) & 0x0FFF
118114
subsec_c = subsec & 0x3F
119-
rand = _getrandbits(56)
115+
rand = secrets.randbits(56)
120116
uuid_int = (timestamp_s & 0x0FFFFFFFFF) << 92
121117
uuid_int |= subsec_a << 80
122118
uuid_int |= subsec_b << 64

test/test_uuid6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_uuid7_same_nanosecond(self, mocktime):
5252
uuid7_1 = uuid7_2
5353

5454
@patch("uuid6._last_v6_timestamp", 1)
55-
@patch("uuid6._getrandbits", return_value=678)
55+
@patch("secrets.randbits", return_value=678)
5656
@patch("time.time_ns", return_value=12345)
5757
def test_uuid6_fields_without_randomness(self, mocktime, mockrand):
5858
uuid6_1 = uuid6(clock_seq=123)

0 commit comments

Comments
 (0)