Skip to content

Commit 0e56cdf

Browse files
committed
Add randomness to the ID to make it more unique.
1 parent 9076e41 commit 0e56cdf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

async_substrate_interface/utils/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import importlib
22
from itertools import cycle
3+
import random
4+
import string
35

46
id_cycle = cycle(range(1, 999))
57

68

7-
def get_next_id():
8-
return next(id_cycle)
9+
def get_next_id() -> str:
10+
"""
11+
Generates a pseudo-random ID by returning grabbing the next int of a range from 1-998, and prepending it with
12+
two random ascii characters.
13+
"""
14+
random_letters = "".join(random.choices(string.ascii_letters, k=2))
15+
return f"{random_letters}{next(id_cycle)}"
916

1017

1118
def hex_to_bytes(hex_str: str) -> bytes:

0 commit comments

Comments
 (0)