Created
August 3, 2018 00:12
-
-
Save taotao54321/4b0a491a6b06eace1b288a449fc85e48 to your computer and use it in GitHub Desktop.
NES Dr.Mario RNG simulator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
RAND_INI = 0x8988 | |
def BIT(x, i): | |
return (x>>i) & 1 | |
def rand_update(r): | |
bit = BIT(r,1) ^ BIT(r,9) | |
r >>= 1 | |
r |= bit << 15 | |
return r | |
def main(): | |
r = RAND_INI | |
s = set() | |
s.add(r) | |
while True: | |
print(f"0x{r:04X}") | |
r = rand_update(r) | |
if r in s: break | |
s.add(r) | |
#print(len(s)) | |
if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment