diff --git a/pySim/esim/saip/param_source.py b/pySim/esim/saip/param_source.py index c2e6ed3b..15cbe7b6 100644 --- a/pySim/esim/saip/param_source.py +++ b/pySim/esim/saip/param_source.py @@ -129,15 +129,26 @@ class RandomSourceMixin: class RandomDigitSource(DecimalRangeSource, RandomSourceMixin): """return a different sequence of random decimal digits each""" name = "random decimal digits" + used_keys = set() def get_next(self, csv_row:dict=None): - val = self.random_impl.randint(*self.val_first_last) + # try to generate random digits that are always different from previously produced random bytes + attempts = 10 + while True: + val = self.random_impl.randint(self.first_value, self.last_value) + if val in RandomDigitSource.used_keys: + attempts -= 1 + if attempts: + continue + RandomDigitSource.used_keys.add(val) + break return self.val_to_digit(val) class RandomHexDigitSource(InputExpandingParamSource, RandomSourceMixin): """return a different sequence of random hexadecimal digits each""" name = "random hexadecimal digits" numeric_base = 16 + used_keys = set() def __init__(self, input_str:str): super().__init__(input_str) @@ -152,7 +163,17 @@ class RandomHexDigitSource(InputExpandingParamSource, RandomSourceMixin): self.num_digits = num_digits def get_next(self, csv_row:dict=None): - val = self.random_impl.randbytes(self.num_digits // 2) + # try to generate random bytes that are always different from previously produced random bytes + attempts = 10 + while True: + val = self.random_impl.randbytes(self.num_digits // 2) + if val in RandomHexDigitSource.used_keys: + attempts -= 1 + if attempts: + continue + RandomHexDigitSource.used_keys.add(val) + break + return b2h(val) class IncDigitSource(DecimalRangeSource):