Snowiiii / Pumpkin

Empowering everyone to host fast and efficient Minecraft servers.
MIT License
591 stars 25 forks source link

implement xoroshiro128 RNG #66

Closed kralverde closed 2 weeks ago

kralverde commented 2 weeks ago

A rust implementation of one of Minecraft's RNGs: XOROshiro128, including tests cases against the results of equivalent java code

Snowiiii commented 2 weeks ago

Hey i actually never heard of XOROshiro128. Can you may explain a bit?. It looks like its an random generator. I wonder where Mojang uses this implementation

Snowiiii commented 2 weeks ago

I also found that rust rand crate has xoshiro128 aswell https://github.com/rust-random/rand/blob/79f1b0ffdbc8605c99ce8348d40ee073a2a7bd0f/src/rngs/xoshiro128plusplus.rs#L17

kralverde commented 2 weeks ago

I never heard of it either, my code is basically 1-1 of the Minecraft Java. I saw the rust crate too, but it gives different values for the same seed as the Minecraft one

kralverde commented 2 weeks ago

Actually let me double check myself

kralverde commented 2 weeks ago

Yeah, I just used this as a wrapper around the rust implementation and the tests failed. It may have been user error, but this works and I think is good enough (TM)

kralverde commented 2 weeks ago

We can always come back to it and change the internals, I just wanna get a stepping stone for chunk generation out of the way

kralverde commented 2 weeks ago

Oh, i think I spotted an error on my side. Alright I'm hooked now, I'll see if I can get the rust crate working as a back-end implementation

kralverde commented 2 weeks ago

I can confirm that the rust implementation uses different magic numbers than the java version. I refactored a bit, but I am confident that this is what we should use for the XorOshiro128 implementation

Snowiiii commented 2 weeks ago

Thank you @kralverde