Page 1 of 1
[Done] math.random() question
Posted: Wed May 09, 2018 9:01 pm
by TheSAguy
So I noticed that "math.random(100)" is not truly random.
I get the same value each time I load the game.
Is there anything else that I should use?
Thanks.
Re: math.random() question
Posted: Wed May 09, 2018 9:03 pm
by Bilka
Afaik you can't seed math.random(). You can seed
LuaRandomGenerator, but that will still be deterministic.
Re: math.random() question
Posted: Wed May 09, 2018 9:05 pm
by orzelek
It needs to be this way.
It's a deterministic randomness so it will always give same sequence of random numbers.
You can create random generator in lua - you will need to seed it tho. After that it will produce different sequence of numbers but still a deterministic one.
It's needed to make sure that multiplayer stays in synch - each client and server need to roll same numbers.
Re: math.random() question
Posted: Wed May 09, 2018 9:08 pm
by Klonan
TheSAguy wrote:So I noticed that "math.random(100)" is not truly random.
I get the same value each time I load the game.
Is there anything else that I should use?
Thanks.
It depends on the map seed and the tick you call it, so using it for runtime operations should be random enough
For, say, data stage, or specific scenario (init) uses, you can try to see another generator with some values,
Seeding with the current mods in data stage,
Or the length and value of a players username in script usage etc.