lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Oh I didn't see lrandom. That makes things easier, thanks. That said,
I think the documentation should make it clear that math.random will
not produce good results and shouldn't be used for any crypto
whatsoever.

On Sat, Mar 22, 2014 at 2:46 AM, Thijs Schreijer
<thijs@thijsschreijer.nl> wrote:
>> -----Original Message-----
>> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
>> Behalf Of Jeremy Ong
>> Sent: zaterdag 22 maart 2014 10:04
>> To: Lua mailing list
>> Subject: [proposal] Concerns about math.random
>>
>> Looking at the source code for math.random and math.randomseed, I
>> can't help but wonder if the user would be better off not using those
>> functions. The main issue is that random numbers generated from it
>> will be nonuniform. Among many programming circles, rand() is
>> considered harmful.
>>
>> For those that wonder if the small amount of nonuniformity is
>> relevant, I would say it can be surprisingly significant. Of course
>> this is significant for people doing statistical analysis or monte
>> carlo methods but this sort of bias introduced to RNG would be lethal
>> in: scripting a rendering engine, distributing loot drops for a game,
>> randomizing enemies, etc.
>>
>> I know C++ is not everyone's cup of tea, but it should be telling that
>> rand() is to be deprecated in C++14 in favor of <random>, precisely
>> for this reason.
>>
>> My recommendation is an implementation of the mersenne twister
>> (http://en.wikipedia.org/wiki/Mersenne_twister). MT is known to be
>> highly performant and produce high quality random numbers. With the
>> new bit shift operators this is a lot more doable. If there's
>> interest, I may try to provide a reference implementation for people
>> to try.
>>
>> Thoughts?
>>
>> Cheers,
>> Jeremy
>
> I think its limited because of ANSI compilers. A mersenne twister is available as the 'lrandom' library by lhf [1]. A while ago I ran into some limitations myself when using a too large randomseed, see this thread [2]
>
> Thijs
>
> [1] http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/
> [2] http://lua-users.org/lists/lua-l/2013-05/msg00275.html
>
>