Skip to content

Commit 226c3c0

Browse files
authored
Merge pull request #97 from opentensor/feat/thewhaleking/random-non-deterministic
2 parents 682e266 + 78ec657 commit 226c3c0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import asyncio
88
import inspect
99
import logging
10-
import random
1110
import ssl
1211
import time
1312
from hashlib import blake2b
@@ -48,7 +47,12 @@
4847
SubstrateMixin,
4948
Preprocessed,
5049
)
51-
from async_substrate_interface.utils import hex_to_bytes, json, get_next_id
50+
from async_substrate_interface.utils import (
51+
hex_to_bytes,
52+
json,
53+
get_next_id,
54+
rng as random,
55+
)
5256
from async_substrate_interface.utils.cache import async_sql_lru_cache
5357
from async_substrate_interface.utils.decoding import (
5458
_determine_if_old_runtime_call,

async_substrate_interface/sync_substrate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import functools
22
import logging
3-
import random
43
from hashlib import blake2b
54
from typing import Optional, Union, Callable, Any
65

@@ -30,7 +29,12 @@
3029
Preprocessed,
3130
ScaleObj,
3231
)
33-
from async_substrate_interface.utils import hex_to_bytes, json, get_next_id
32+
from async_substrate_interface.utils import (
33+
hex_to_bytes,
34+
json,
35+
get_next_id,
36+
rng as random,
37+
)
3438
from async_substrate_interface.utils.decoding import (
3539
_determine_if_old_runtime_call,
3640
_bt_decode_to_dict_or_list,

async_substrate_interface/utils/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
id_cycle = cycle(range(1, 999))
77

8+
rng = random.Random()
9+
810

911
def get_next_id() -> str:
1012
"""
1113
Generates a pseudo-random ID by returning the next int of a range from 1-998 prepended with
1214
two random ascii characters.
1315
"""
14-
random_letters = "".join(random.choices(string.ascii_letters, k=2))
16+
random_letters = "".join(rng.choices(string.ascii_letters, k=2))
1517
return f"{random_letters}{next(id_cycle)}"
1618

1719

0 commit comments

Comments
 (0)