Java Random reimplemented incorrectly
A few members of our community have been studying the latest snapshot code and they claim to have found an issue in the class LegacyRandomSource.
Java documentation specifies that Next(bits) should return (int)(seed >>> (48 - bits)). However, current code seems to return (int)(seed >> (48 - bits)).
This could cause future issues related to nextInt returning negative numbers in rare cases, and incomplete parity with Bedrock.
Members that confirmed this issue in our community: cortex and MrSpike.
Created Issue:
Java Random reimplemented incorrectly.
A few members of our community have been studying the latest snapshot code and they claim to have found an issue in the class LegacyRandomSource.
Java documentation specifies that Next(bits) should return (int)(seed >>> (48 - bits)). However, current code seems to return (int)(seed >> (48 - bits)).
This could cause future issues related to nextInt returning negative numbers in rare cases, and incomplete parity with Bedrock.
A few members of our community have been studying the latest snapshot code and they claim to have found an issue in the class LegacyRandomSource.
Java documentation specifies that Next(bits) should return (int)(seed >>> (48 - bits)). However, current code seems to return (int)(seed >> (48 - bits)).
This could cause future issues related to nextInt returning negative numbers in rare cases, and incomplete parity with Bedrock.Members that confirmed this issue in our community: cortex and MrSpike.
A few members of our community have been studying the latest snapshot code and they claim to have found an issue in the class
LegacyRandomSource.
Java documentation specifies that Next(bits) should return (int)(seed >>> (48 - bits)). However, current code seems to return (int)(seed >> (48 - bits)).This could cause future issues related to nextIntreturning negative numbers in rare cases, and incomplete parity with Bedrock.Members that confirmed this issue in our community: cortex and MrSpike.
A few members of our community have been studying the latest snapshot code and they claim to have found an issue in the class LegacyRandomSource.
Java documentation specifies that Next(bits) should return (int)(seed >>> (48 - bits)). However, current code seems to return (int)(seed >> (48 - bits)).
This could cause future issues related to nextInt returning negative numbers in rare cases, and incomplete parity with Bedrock.Members that confirmed this issue in our community: cortex and MrSpike.
Java Random reimplemented incorrectly.

For reference, https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#next-int- specifies >>> (logical shift operation) usage.
Would fixing this change the seed features?
Can confirm in 1.18 Pre-release 1.
This issue isn't relevant anymore, as LegacyRandomSource is not being used in any important place of the game anymore, except for stronghold layouts, which can't be affected by that problem. (Mojang switched to XoroShiro128++ for features in pre-release 1)
It looks like LegacyRandomSource is still used (
MC-249933).Mojang's code in `next` looks like this:
So isn't `m` always positive here? I don't see where the difference between >> and >>> in this case
I cannot reproduce using MC@h Matt 's repro instructions. I can only assume that their JavaRnd implementation is not equivalent to Mojang's RandomSource, or maybe that Mojang fixed it since the issue was reported. Here's the code I ran using Mojang's actual RandomSource:
And the output:
I think this issue can be closed.