We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3f36754 commit 5fa6582Copy full SHA for 5fa6582
1 file changed
agentlightning/utils/id.py
@@ -7,12 +7,18 @@
7
8
9
def generate_id(length: int) -> str:
10
- """Generate a random ID of the given length.
+ """Generate a random hexadecimal ID of the given length.
11
12
Args:
13
- length: The length of the ID to generate.
+ length: The desired length of the generated ID. Must be a positive integer.
14
15
Returns:
16
- A random ID of the given length.
+ A random hexadecimal ID string of the given length.
17
+
18
+ Raises:
19
+ ValueError: If length is not a positive integer.
20
"""
21
+ if length <= 0:
22
+ raise ValueError("length must be a positive integer")
23
24
return hashlib.sha1(uuid.uuid4().bytes).hexdigest()[:length]
0 commit comments