Page 2 of 4

Re: RandomLua Library

Posted: Thu Jul 28, 2011 8:25 pm
by TechnoCat
Using this library and a common seed will produce the same results on all systems right?

Re: RandomLua Library

Posted: Thu Jul 28, 2011 10:27 pm
by linux-man
I hope so...
Updated again to correct a bug in mwc:randomseed. I was not reseting a variable parameter.

Re: RandomLua Library

Posted: Fri Jul 29, 2011 12:20 pm
by T-Bone
What are the benefits in comparison to math.random()?

Re: RandomLua Library

Posted: Fri Jul 29, 2011 1:01 pm
by kikito
If I've understood it correctly, math.random returns different values with the same seed depending on the platform (mac, at least). This might be inconvenient if you want the exact same results in all platforms; But I might be mistaken.

Re: RandomLua Library

Posted: Fri Jul 29, 2011 3:20 pm
by bmelts
Yeah, math.random's results are platform-dependent, even with identical seeds. The distribution is, too - some implementations of math.random() are better at generating a pseudorandom distribution of numbers than others.

On the other hand, it is faster than a pure Lua implementation, because the function it calls is part of the C standard library. As you can see from linux-man's benchmarks, some algorithms are slower than others, but all of them are slower than they would be in C/asm form.

Re: RandomLua Library

Posted: Fri Jul 29, 2011 3:28 pm
by slime
You could probably get a (relatively) wicked fast RNG using LuaJIT and its FFI.


problem, bartbes?

Re: RandomLua Library

Posted: Sat Jul 30, 2011 6:46 pm
by linux-man
I'm using mwc and quite happy with the results. It's fast enough for casual use. Beside, from what I saw, mwc is as good as math.random() on linux and way better than the Mac implementation (I wonder why).

Re: RandomLua Library

Posted: Tue Aug 09, 2011 12:39 am
by genericdave
It seems to be completely broken on osx. Here's my output from your example:

Code: Select all

6 3 4 10
1 5 5 1
6 7 9 1
1 9 7 1
6 9 5 4
1 3 3 1
6 1 5 10
1 3 9 10
6 9 9 1
1 3 1 3

0
38011930
2.22129e+09
0
50726607
3.00238e+09
0
4194433
3.83448e+09
0
Totally different from your results and not random in the slightest. I ran into a similar problem when attempting to make my own random number generator. The variables end up being too big at one point and lua sometimes rounds them off. Ideally, a decent generator should be part of Love itself.

Re: RandomLua Library

Posted: Sun Aug 14, 2011 9:57 pm
by linux-man
Many thanks for your report. I now had a little time for testing and found that twister code was broken. To correct it I needed to round all the calculations to 31 bits. I guess the code is now an "adapted Mersenne Twister" and maybe the randomness sucks now (but I don't really think that).
I updated the lib with a new test and added a love test file.
I don't have a Mac right now, but the results are the same on Linux 32/64 and Windows XP. Can't imagine how they can be broken on Mac. Can you please test again?

Re: RandomLua Library

Posted: Sun Aug 21, 2011 11:55 pm
by genericdave
Alright, I figured out what the problem was. It works just fine in the .love file you posted. Before, however, I was using a non-love lua interpreter (specifically, AGen). I guess the way that different interpreters deal with variable sizes can cause different results. Love seems to play nicely with the lib on all systems, but certain interpreter environments totally break things.