Love needs a quality PRNG

Issue #3 resolved
created an issue

The default PRNGs supplied as part of the stdlib (and thus, the one lua exposes in math.*) are implementation defined (aka, no assurance of consistency between systems), and usually rubbish to boot.

While games are generally non-critical, the tendency of games to both make the results of individual random numbers apparent to the user, and the tendency to make randomised decisions based on other randomised decisions tends to exasperate and highlight the flaws in the PRNGs they use, often resulting in statistical aberrations up to and including (in rare cases) the //effective removal// of decision branches due to the mathematical impossibility of the PRNG in generating the required sequence of numbers! +

While PRNGs //can// be implemented in pure lua, its often a tedious process beyond the skills of the lovers who actually need them, while producing a PRNG that runs far slower than the native rand. ++

Adding a decent PRNG implementation to Love would improve both the quality and inter-platform consistency of the psudorandom numbers available to lovers.

Exactly which PRNG you add I'm not overly concerned with. While LHF has a mtwister implementation on his site, and certainly its a safe and common choice, Wikipedia suggests there might be better PRNGs with similar or superior performance.

^^ + For a time there, it seems like a right-of-passage for a rogue-like project to find just such a bug.

^^ ++ One pure-lua PRNG I tried was about //10x// slower. and supposedly it was one of the faster ones.

Comments (9)

  1. Anonymous

    Well, I didn't want to add C code to lua atm., so I ended up doing this to get the most apparent enthropy out of the lua pseudo random generator on win32: function myRandom:getInt16() self._n= self._n+1 local a= math.random(0,65535) local b= math.random(0,65535) return self.xor_bits_16(a,self.invert_bits_16(b)) end Clearly, it isn't nice to have to go so far out. --Peter

  2. Bill Meltsner

    There's several options here, the easiest of which is probably just including lrandom with LÖVE as we do with luasocket, and letting people use it accordingly. We could also take a standard C Mersenne twister and wrap it into a love.random module or something.

    Either way, not happening for 0.7.0.

  3. Anonymous

    How is this looking for 0.8.0? I'd love to see native support for a Complimentary Multiply With Carry RNG in Löve.

  4. Log in to comment