Skip to content

Improve Random Block Selection RNG#11537

Closed
ScriptLineStudios wants to merge 2 commits into
PaperMC:masterfrom
ScriptLineStudios:improve-block-selection-RNG
Closed

Improve Random Block Selection RNG#11537
ScriptLineStudios wants to merge 2 commits into
PaperMC:masterfrom
ScriptLineStudios:improve-block-selection-RNG

Conversation

@ScriptLineStudios
Copy link
Copy Markdown

@ScriptLineStudios ScriptLineStudios commented Oct 31, 2024

The RNG used in selecting random blocks for updates, is fundamentally flawed, plotting some values sampled from this RNG clearly indicates the problem:

weak

Modifying the algorithm to include a couple more terms yields a much nicer and random looking result:

strong

Additionally this PR removes the deprecated threadSafeRandom object used for providing the client with seeds for sound variant selection in favor of using the improved randValue :D

@ScriptLineStudios ScriptLineStudios requested a review from a team as a code owner October 31, 2024 11:57
@lynxplay
Copy link
Copy Markdown
Contributor

lynxplay commented Oct 31, 2024

Thank you for the PR.

We are not going to deviate from vanilla's logic at the whim that it "looks more random".
Mojangs usage of the deprecated annotation is up to them, as long as they use it, there is 0 reason for us to "replace it"

@lynxplay lynxplay closed this Oct 31, 2024
@ScriptLineStudios ScriptLineStudios deleted the improve-block-selection-RNG branch October 31, 2024 12:06
@vadcx
Copy link
Copy Markdown

vadcx commented Oct 31, 2024

I remember some fork a while ago attempted to optimize block update RNG at some point.

@ScriptLineStudios If you can prove that this RNG pattern causes problems, you would need to raise issues with Mojang directly? Otherwise it must have been a deliberate choice, the same magic number is used here as an increment:

@Spottedleaf
Copy link
Copy Markdown
Member

Hi,

I know that this PR is old but I wanted to clarify something.

Paper uses an LCG random for random block selection during random ticking. Specifically, we take the lower 12 bits of Random#nextInt().

See https://github.com/Tuinity/Moonrise/blob/mc/1.21.3/src/main/java/ca/spottedleaf/moonrise/mixin/random_ticking/ServerLevelMixin.java

If you find an issue with this implementation, you may open an issue on https://github.com/Tuinity/Moonrise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

4 participants