-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcg.py
More file actions
31 lines (22 loc) · 733 Bytes
/
lcg.py
File metadata and controls
31 lines (22 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Implements a Linear Congruential Generator as used by
Pokemon Colloseum for pRNG
"""
from conversion import hex_str_to_double
class LCG():
def __init__(self, seed):
assert isinstance(seed, int)
self.state = seed
def generate(self, generation_constant=65536.0):
"""
simulates subroutine 801adc7c
generation constant is from rtoc
"""
assert isinstance(generation_constant, float)
self.state = (self.state * 214013 + 2531011) & 0xffffffff
n = 0x4330000000000000 | (self.state >> 16)
n = hex_str_to_double(hex(n)[2:])
n -= 4503599627370496.0
n /= generation_constant
assert isinstance(n, float)
return n