0.9.0 Love.math

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Grubby
Prole
Posts: 35
Joined: Sat Jun 01, 2013 2:46 am

0.9.0 Love.math

Post by Grubby » Sun Dec 15, 2013 4:06 am

Is the PRNG crypto strong or not? If not, then I'd suspect issues with value(s) spread. What math is actually being used to create the PRNG values?

Just curious...

User avatar
slime
Solid Snayke
Posts: 2887
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: 0.9.0 Love.math

Post by slime » Sun Dec 15, 2013 4:25 am

It is not, and it's not supposed to be. PRNGs in games almost never need that characteristic - performance, on the other hand, is very important. It is also very important for PRNGs in games to be seedable and reproducible, so you can use the same seed to get the same results every time (if you need.) The latter characteristic is used to great effect in games like Minecraft - or more subtly in certain types of save-files for some games.

love.math.random uses a 64-bit Xorshift algorithm.

http://www.javamex.com/tutorials/random ... hift.shtml
https://bitbucket.org/rude/love/src/tip ... at=default

User avatar
gim
Prole
Posts: 10
Joined: Sat Dec 07, 2013 7:09 pm

Re: 0.9.0 Love.math

Post by gim » Mon Dec 16, 2013 5:04 pm

It is not crypto strong, but from what I understand from what you've written in other thread, you don't need crypto-strong RNG.
I guess, you only need RNG, with some good properties.
As slime has written, love.math.random uses Xorshift (which actually is LFSR with primitive polynomial).

Used xorshift will provide full period, but I think (although I haven't tested) it'll fail statistical tests (i.e. Crash + Smallcrush : http://en.wikipedia.org/wiki/TestU01).

But fear not!, math.random under luajit uses Tausworthe prng, which should be quite good.

Besides, I don't think there would be problem with adding (additionaly) Mersenne Twister to love (that would probably require permission of the author, but from what I've heard, that is not a problem)
"We must have perseverance and above all confidence in ourselves. We must believe that we are gifted for something, and that this thing, at whatever cost, must be attained." - Marie Skłodowska-Curie

User avatar
slime
Solid Snayke
Posts: 2887
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: 0.9.0 Love.math

Post by slime » Mon Dec 16, 2013 7:10 pm

One of the web pages I linked above says this:
[Xorshift's] resulting values pass Marsaglia's "Diehard battery" of statistical tests for randomness. L'Ecuyer & Simard (2007) also found that values of 13, 7 and 17 [which LÖVE uses] fail on only 7 of the 160 tests of their BigCrush battery.

User avatar
gim
Prole
Posts: 10
Joined: Sat Dec 07, 2013 7:09 pm

Re: 0.9.0 Love.math

Post by gim » Mon Dec 16, 2013 10:57 pm

slime wrote:One of the web pages I linked above says this:
[Xorshift's] resulting values pass Marsaglia's "Diehard battery" of statistical tests for randomness. L'Ecuyer & Simard (2007) also found that values of 13, 7 and 17 [which LÖVE uses] fail on only 7 of the 160 tests of their BigCrush battery.
haven't noticed that, good to know it fails only on 7 (I knew it passes "diehard" tests - those are really basic ones)
"We must have perseverance and above all confidence in ourselves. We must believe that we are gifted for something, and that this thing, at whatever cost, must be attained." - Marie Skłodowska-Curie

User avatar
hryx
Party member
Posts: 110
Joined: Mon Mar 29, 2010 2:28 am
Location: SF<CA<USA

Re: 0.9.0 Love.math

Post by hryx » Wed Dec 18, 2013 4:30 am

slime wrote:or more subtly in certain types of save-files for some games.
You got my attention with that. Can you explain a use case pertaining to save files?

User avatar
Hexenhammer
Party member
Posts: 175
Joined: Sun Feb 17, 2013 8:19 am

Re: 0.9.0 Love.math

Post by Hexenhammer » Wed Dec 18, 2013 5:40 am

hryx wrote:
slime wrote:or more subtly in certain types of save-files for some games.
You got my attention with that. Can you explain a use case pertaining to save files?
Instead of saving the current world state (which maybe big and complex) you just save the RNG seed which created that state. "Loading" a game then means recreating the world state by re-seeding your RNG to the saved seed and running world gen. Of course that only works if the world state in question is static after generation. But in theory you could also handle partially dynamic world state by saving the RNG seed + the difference between the world state and the result of running world gen with that seed.

You may also want to save the RNG state to stop players from just reloading when they get an unfortunate dice roll or something. E.g. turn-based game, player saves at the beginning of the turn, does something with a 70% chance of success, fails.. if you do not save the RNG state he could now simply reload and try again until he succeeds. But if the RNG state is saved he always gets the same result there and thus has to accept it.

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests