Skip to content

Instantly share code, notes, and snippets.

@taotao54321
Created August 3, 2018 00:12
Show Gist options
  • Save taotao54321/4b0a491a6b06eace1b288a449fc85e48 to your computer and use it in GitHub Desktop.
Save taotao54321/4b0a491a6b06eace1b288a449fc85e48 to your computer and use it in GitHub Desktop.
NES Dr.Mario RNG simulator
#!/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