lua-users home
lua-l archive

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

On 17/03/2010, at 6:54 AM, Javier Guerra Giraldez wrote:

> On Tue, Mar 16, 2010 at 11:17 AM, Christopher Eykamp <> wrote:
>> I'm running on Windows, embedded in a C++ app.  The chances of a re-seed
>> seem minimal, as the two lines I posted are executed one after the other in
>> the same file.
>> I have temporarily resolved my problem by overwriting the random function to
>> call my C++ program and use it's random function, which seems to be...
>> well... random.
>> If the seeds were the same, I would expect the results I see, but they're
>> clearly different.
> i've just tried this:
> function tr(seed)
>  math.randomseed( seed )
>  print ("Seed: "..seed,
> math.random(10000),math.random(10000),math.random(10000),math.random(10000))
> end
> for _,s in ipairs
> ({3063121584,2428144928,3559301251,4287790062,2737803158,2458923424})
> do
>  tr(s)
> end

On windows I got the same results as Christopher.

Lua just uses the system's rand, and what you're learning is that rand isn't a great random number generator, and that Windows' implementation is not the best.  lhf's lrandom is surely better: