Emtree with Random Seed (SOLVED)

Hey there,

I’m dabbling with making my own Match 3 game, and I’ve pilfered Britzl’s lovely emthree library to make it with, however I noticed that each time I load my game it starts with the exact same layout. I then took a look at the Ocean Commotion demo and noticed it did the exact same thing. Is there a way to make the board generate layouts from a random/pseudorandom seed so we don’t start with the same layout each time?

Thanks,
Dan.

1 Like

Emthree uses math.random() but it does not set the seed, that’s for you to set.

Set a random seed to time before calling any emthree functions and make sure you call math.random() a few times after to get good values.

math.randomseed(os.time)
math.random()
math.random()
math.random()

Note about math.randomseed() if you set it to the same value it will generate the same values in the same order every time. That’s how PRNG works. Setting the seed to time makes it unique, if 2 players started to play at the very exact time they would have the same “random” experience. It’s how Minecraft worlds can generate the same way too for everyone who uses the same seed, generation is done through stepped RNG generation.

You could modify Emthree to use PCG Random Number Generator instead of the builtin math.random() to improve random quality.

6 Likes

Thank you very much, this information is extremely helpful!

1 Like