samedi 8 avril 2023

How do I use an lcg "non-sequentially"

I want to create a game that is a 2d dungeon, each tile in the dungeon will have the same chance of being a solid or air block, the dungeon will be infinite and every time you spawn a dungeon it will be with a seed, same seed, same dungeon.

Thinking a bit I came to the conclusion that I should use a rng in a different way, to determine if a box is solid or not, the x and y coordinates of that box are taken and multiplied, then the seed of the dungeon is added and the result is fed into the rng as a seed, which is an lcg. In this way, it is very easy to program.

The problem here is that the lcgs don't work that way, and if you try to do it like this, in the coordinate line x=0 or y=0, the seed of those cells will always be that of the dungeon, so the same will be generated number. And in the rest of the cells a pattern is generated that is clearly not random. This is because the lcg behaves like a function.

I have thought that the solution is that when calculating the seed for each box, the formula is more complex, adding randomness to the final seed, but I can't find a good formula.

In the formula to calculate the seed of each cell, I have tried to use trigonometric functions, but I don't know if it is the best way, it could be that the pattern was more random but that the numbers did not take long to repeat themselves.




Aucun commentaire:

Enregistrer un commentaire