Is your feature request related to a problem? Please describe.
As I understand, Lua's math.random depends on OS' implementation of them.
At the moment math.random returns different values even with same seed (server and client runned on different platforms). So it can't be used for world generation, etc (I have to send huge amount of data from server to clients or use 3rd party libraries)
Describe the solution you'd like
Add own random functions which will use same algorithm on each platform.
Describe alternatives you've considered
3rd party libraries written on Lua may significantly reduce the perfromance if it used a lot
Additional context
no
Interesting...
Lua likely depends on the C version of rand(), so probably using C++'s rand() would yield the same results.
Btw, https://love2d.org/forums/viewtopic.php?t=84496 they say that L脰VE has a consistent PRNG:
Yeah, that's a given; it's also consistent across all platforms and Lua interpreters (while LuaJIT packs a consistent PRNG, L脰VE can also use standard Lua).
We don't need to reinvent the wheel here. C++ has had <random> since C++11. We could simply expose a std::mt19937 instance to Lua. That would also give us deterministic behavior as mt19937 is strictly defined.
Things to discuss:
math.random or should we introduce our own function name?Do we want scripts to be able to create PRNG instances (might be cool for random numbers synchronized across clients)
I think this would be good. This would also be beneficial for multi-gamemode servers.
replace default
As long as we can create RandomGenerator instances, I don't see much benefit to having our own equivalent to math.random (or replacing the default math.random).
Imo the only benefit would be making it slightly easier to use, but if your code depends on a consistent PRNG, you probably wouldn't mind going through the minor inconvenience of instantiating your own generator.
global vs. per-resource PRNG
If we do intend to have a simple function (without the need of instantiating a generator):
math.random, we may want to just use a single PRNG for everythingmath.random function, I think _per-resource_ would be goodPer-resource PRNG, please.
Otherwise the result may be different (especially if https://github.com/multitheftauto/mtasa-blue/issues/918 implemented)
upd: does not matter if instances used