diff --git a/pysollib/pysolrandom.py b/pysollib/pysolrandom.py index 440236b0..f60142e2 100644 --- a/pysollib/pysolrandom.py +++ b/pysollib/pysolrandom.py @@ -79,7 +79,19 @@ def constructRandom(s): seed = int(s) if 0 <= seed < 32000: return LCRandom31(seed) - return pysol_cards.random.MTRandom(seed) + # print("MTRandom", seed) + ret = pysol_cards.random.MTRandom(seed) + init_state = ret.getstate() + ret.initial_seed = initial_seed = seed + + def _reset(self=ret): + # print("called reset") + ret.setSeed(initial_seed) + return + ret.seed = ret.initial_seed + ret.setstate(init_state) + ret.reset = _reset + return ret # test diff --git a/tests/lib/pysol_tests/ms_deals1/__init__.py b/tests/lib/pysol_tests/ms_deals1/__init__.py index 80d092e1..fa2bd109 100644 --- a/tests/lib/pysol_tests/ms_deals1/__init__.py +++ b/tests/lib/pysol_tests/ms_deals1/__init__.py @@ -186,3 +186,16 @@ KS 7S 5H 3H TS 3S 5D 9C JH 8H 3D 4D QC KH 6H 6C TC 2C 7D ''', 'ms100001') + + seed = 24000024 + rand = constructRandom(str(seed)) + expected0 = rand.randint(0, 100) + expected1 = rand.randint(0, 100) + rand.reset() + got0 = rand.randint(0, 100) + got1 = rand.randint(0, 100) + # TEST + self.assertEqual( + [got0, got1, ], + [expected0, expected1, ], + "same results after reset()",)