Problem with Random!

Guys, after a finish my problems with tilemaps… i get stucked on next subject … my random dungeon is not random … i rebuild the project and it comes the same and the same … forever.
I checked if i had problem on using math.random(4,7) but i check on lua and it should work.

Any idea what is happening?

Did you use math.randomseed?

Handy Google-search

1 Like

Like Ragnar said you can do this once before you use math.random

math.randomseed(os.clock()*100000000000)

However to get really good random numbers you’ll want to use something like

@admins can we get .lua files approved for upload?

3 Likes

I added lua files in the settings.

2 Likes

Ty guys… like Ragnar said i was missing the randomseed … in the right place … after i changed to init function. Finds started to work.

But i used math.randomseed(os.time()) … it worked , i read in some place that should be math.randomseed(os.time() - os.clock()*1000).

someoe could share an opinion?

Pkeod … all that really makes the difference to simulate … d6, d8, d10 etc? If the diference is big i will give it a try.

Ty everybody :smiley:
You are all very fast.

2 Likes

I’m not a super expert at Lua yet so I can’t comment on any flaws the standard math.random may have. But I think it’s still a good idea to use the non-standard for gamedev related randomness. Many games do use standard random functions and so have flaws such as having randomly generated game boards, but every 200 levels or so you are statistically guaranteed to have played the same exact level at least twice…

By the way, if you want to generate dungeons that are not all the same but each is constructed the same every time that specific level is generated you can use a method of building such as setting the seed each time you generate a random number to generate something based on like: level id + step. You reset the seed, and then generate a value immediately with each step. This ensures that you generate the same values every time. This is useful if you want to build a daily challenge type of mode (seen in games like Spelunky or Crypt of the NecroDancer) where everyone in the world gets the same dungeons exactly to play each day without relying on a server to deliver dungeon data. However a thing to be aware of with this is that different OS may have different way of doing functions which the PRNG relies on, which means the random steps may not always be the same on Windows vs Linux… you would have to test.

2 Likes

oh ty that was very very interesting … i will think on something like this … but most interesting thing was that is possible to generate identical dungeons for different ppl. Ty alot

1 Like