diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index e8a95aa..6b50d90 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -7,7 +7,6 @@ import asyncio import inspect import logging -import random import ssl import time from hashlib import blake2b @@ -48,7 +47,12 @@ SubstrateMixin, Preprocessed, ) -from async_substrate_interface.utils import hex_to_bytes, json, get_next_id +from async_substrate_interface.utils import ( + hex_to_bytes, + json, + get_next_id, + rng as random, +) from async_substrate_interface.utils.cache import async_sql_lru_cache from async_substrate_interface.utils.decoding import ( _determine_if_old_runtime_call, diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index f463f2f..339e9b6 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -1,6 +1,5 @@ import functools import logging -import random from hashlib import blake2b from typing import Optional, Union, Callable, Any @@ -30,7 +29,12 @@ Preprocessed, ScaleObj, ) -from async_substrate_interface.utils import hex_to_bytes, json, get_next_id +from async_substrate_interface.utils import ( + hex_to_bytes, + json, + get_next_id, + rng as random, +) from async_substrate_interface.utils.decoding import ( _determine_if_old_runtime_call, _bt_decode_to_dict_or_list, diff --git a/async_substrate_interface/utils/__init__.py b/async_substrate_interface/utils/__init__.py index e295e02..d0ad6eb 100644 --- a/async_substrate_interface/utils/__init__.py +++ b/async_substrate_interface/utils/__init__.py @@ -5,13 +5,15 @@ id_cycle = cycle(range(1, 999)) +rng = random.Random() + def get_next_id() -> str: """ Generates a pseudo-random ID by returning the next int of a range from 1-998 prepended with two random ascii characters. """ - random_letters = "".join(random.choices(string.ascii_letters, k=2)) + random_letters = "".join(rng.choices(string.ascii_letters, k=2)) return f"{random_letters}{next(id_cycle)}"