Skip to content

Instantly share code, notes, and snippets.

@mdnestor
Last active May 9, 2024 09:30
Show Gist options
  • Save mdnestor/fb360a5220f51872ac83e99c8792e6d4 to your computer and use it in GitHub Desktop.
Save mdnestor/fb360a5220f51872ac83e99c8792e6d4 to your computer and use it in GitHub Desktop.
# Algorithm Minecraft uses to convert world seeds to integers
# Shows why `creashaks organzine` yields seed 0, whereas by design manually inputting seed 0 uses random seed.
def seed(x: str) -> int:
if isinstance(x, int):
return x
s = 0
for c in x:
s = ((31*s + ord(c)) ^ 0x80000000) & 0xFFFFFFFF - 0x80000000
return s
print(seed("creashaks organzine"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment