Huh! I can’t believe I missed that when searching the Shared Code database!
Thanks @nick for the link!
Huh! I can’t believe I missed that when searching the Shared Code database!
Thanks @nick for the link!
I’m gonna risk tossing this out there in the spirit of a “public service announcement”, not intending to come across as a jerk just for criticizing someone else’s code, but…
Every game may have its own unique needs for random numbers, and not all PRNG’s are created equal. For example, what might be appropriate for a kids’ “flip-match” game might not be appropriate for shuffling cards in a gambling game (where some proxy for real money might be involved). So, choose wisely.
The generator linked above has some not-insignificant limitations. (or, more bluntly: it’s quite poor at simulating true randomness) You could do far better even with a simple “one-liner” LCG.
I know of which I speak, but I wouldn’t expect anyone to take my word for it – do your own due diligence as suits your own particular application. This is a well-studied field, and there are many known implementations with known statistical properties, at least one of which is likely to be suitable.
It’s good advice.
For my particular situation it’s only for calculating positions of objects on screen and they need to be the same on Android/iOS, so simulating true randomness isn’t a requirement.
Would this work
math.randomseed( os.time() )
No, the problem is that Android and iOS have different algorithms to generate random numbers.
I ended up using this library:
Would this work
math.randomseed( os.time() )
No, the problem is that Android and iOS have different algorithms to generate random numbers.
I ended up using this library: