I'm trying to write a program that mimics the way Minecraft turns strings into numbers to use them as seeds for world generation, but I just can't get it to work! The code I'm using is as follows:

0→num
For x,1,dim(seed)
ord(mid(seed,x,1))→c
num + c * 31^(dim(seed)-x)→num
EndFor

I've tried several +1 and -1 variations in the exponent, but none of them give the same number as MC does.
Based on reading https://www.quora.com/How-do-Hashcode-Minecraft-seeds-work-mathematically?top_ans=256185336 , strings that can be cast to integers between negative and positive 2^64 are used directly, and strings are run through the Java hashCode() method on strings. It's notable that the author of that comment indicates it's using 16-bit Unicode character codes, but if you're dealing with ASCII-type characters (letters, numbers, and simple punctuation), that should be irrelevant to you. It's also quite important to note that the output of hashCode() is a signed 32-bit integer, so taking the modulus of the value accordingly would be necessary.

I'm rusty on my 68k TI-BASIC, but it would be something like:

Code:
``` 0→num For x,1,dim(seed) ord(mid(seed,x,1))→c num + c * 31^(dim(seed)-x)→num mod(num,2^32)→num EndFor ```
Ah, I had forgotten to apply the modulus! Works great, thanks for the help~

Oh, I wonder as well, do Bedrock versions use a different hash function than Java does? It makes sense of they do, but lately the devs have been working on parity between Bedrock and Java, so I'm not sure.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum