mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
temp fix for reset() in pysolfc/mtrandom deals.
See: https://github.com/shlomif/PySolFC/issues/163 . Thanks to @RobertAJMarshall .
This commit is contained in:
parent
e43dcb207c
commit
a219bdb29c
2 changed files with 26 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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()",)
|
||||
|
|
Loading…
Add table
Reference in a new issue