Technical Minecraft Wikia
Advertisement


Random number generation (RNG) manipulation[]

RNG manipulation is a big part of world and player manipulation and uses interactions to manipulate the chance of a random event happening.

Before you jump in[]

If you're not familiar with the Minecraft code, it's suggested that you inform yourself on the basics of Minecraft's mechanics.

A list of useful links:

  • Chunks
  • Redstone
  • Block updates (WIP)
  • Random ticks (WIP)
  • Iron farms and villages (WIP)
  • Spawn mechanics (WIP)
  • Weather (WIP)
  • Tile entities (WIP)

There is also a video tutorial by Xcom6000, which goes into the theme deeply [1]

RNG in the code[]

Before we begin to manipulate the RNG, we need to take a look at the code first.

The following code is pseudo code and NOT licensed by Microsoft inc.

Every randomized action in the game is based on a single pseudo random number generator. The generator has a reset function and a "forward function", which is called whenever a random number is required.

It begins with

rand = new Random();

This sets a random function

Then, if the game requests a new random number, it calls this:

number = rand.nextInt();

This will generate a random number, switching to a new one based on the previous one

Normally, since the output is based on the previous output, this would have the ultimate form of security, since it's the same way one's web browser establishes a secure connection via HTTPS to this server. This, however, is not the case.

To fix this, Mojang could use

number = rand.nextInt(lastNumber)

Reverse engineering the RNG[]

Since we know that the RNG consists of this unbreakable chain of random generations, how do we break it?

Normally it would be like this:

rand = new Random(); --> number = rand.nextInt() ...followed by more nextInt... --> number = rand.nextInt()

And in one part of the chain, "number" would be used to generate something like how many redstone should drop from an ore.

This would normally be very secure, but since there is an autosave function, the randomness is reset for every given number of ticks.


Advertisement