# Reversing a procedural generation

This topic is 2046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Procedurally generated data has a random seed and random values generated by the process. Here is an example of what I mean:

You have a row of windows you want to either be broken or unbroken. You set you seed and loop through the "windows" randomly assigning "broken" or "unbroken" to each according to the output of the random number generator.

This is simple and straight forward......

What if I wanted to do that in reverse? If I started with all the windows "unbroken" and I throw rocks randomly and broke a few of them. I would like to reverse the process until I get THE random seed that would result in generating the windows into that state.

I'm sure it CAN be done, but how?

This process could be very useful in games that have a huge amount of "object states". Like a planet with mineral deposits. If the player collects a certain amount of them, it would be silly for the player to be able to come back to the planet and get those deposits again. And saving the state of each mineral deposit on every planet in every solar system would be crazy!

##### Share on other sites

If I have a random seed of 12345 and with the process, the windows generate:

1,0,1,1,0,0,0,0

where 1=="broken" and 0=="unbroken"

Then every time I go to generate the windows with seed 12345 it will look exactly the same.

If I break a window:

1,0,1,1,0,1,0,0 then the seed 12345 won't generate this result.

There IS some seed that will generate 1,0,1,1,0,1,0,0..... I want to go from the result to the seed. It's not magic, it's logic I am not fully aware of.

##### Share on other sites

This is a SUPER SIMPLE random number generator:

int RNSeed=12345;
int randomnum(void){
RNSeed=abs(RNSeed*8786545643)%987654321;
return RNSeed;
}



With this initial seed, the first time it's called it results in 770159010, and the second time it results in 808599291.

This will happen EVERY time I start with 12345. The problem with reversing the calculation is the modulus of 987654321. Any seed value greater than that number will be some value that can't be found and therefore the previous seed us unknown. The solution would involve a random number generator that can be reversed-- I don't know how to make that (or if it can be made at all).

All of you are either think I don't know how random generators work or you are missing my point entirely.

##### Share on other sites

You have 2 windows and a 1 bit seed. 0 is both windows broken, 1 is both windows intact. You want a seed that leads to only 1 broken window... there isn't one. Now think larger scale and you'll understand why you can't do what you want to do.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 20
• 20
• 11
• 9