# HG changeset patch # User Thibaut Girka # Date 1313361499 -7200 # Node ID 493b503c81e036131b47a129c084ae72431d186f # Parent cb5b27011044a41a5288b751ee836dac8ee2e417 Fix PRNG and add some methods to perform like EoSD diff --git a/pytouhou/utils/random.py b/pytouhou/utils/random.py --- a/pytouhou/utils/random.py +++ b/pytouhou/utils/random.py @@ -16,7 +16,8 @@ from time import time class Random(object): def __init__(self, seed=None): if seed is None: - seed = int(time.time() % 65536) + seed = int(time() % 65536) + self.seed = seed self.counter = 0 @@ -25,12 +26,23 @@ class Random(object): self.counter = 0 - def cycle(self): - # Named this way because the actual return value may be different. + def rand_uint16(self): # Further reverse engineering might be needed. - x = ((seed ^ 0x9630) - 0x6553) & 0xffff + x = ((self.seed ^ 0x9630) - 0x6553) & 0xffff self.seed = (((x & 0x0c000) >> 0xe) + x*4) & 0xffff self.counter += 1 self.counter &= 0xffff return self.seed + + def rand_uint32(self): + # 102h.exe@0x41e7f0 + a = self.rand_uint16() << 16 + a |= self.rand_uint16() + return a + + + def rand_double(self): + # 102h.exe@0x41e820 + return float(self.rand_uint32()) / 0x100000000 +