Re: Determenistic seeding of LuaJIT PRNG from C code

  • From: Mike Pall <mike-1403@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 27 Mar 2014 12:25:18 +0100

Konstantin Olkhovskiy wrote:
> I though of tonumber(<int64_t cdata>), but my concern is about roundings
> and other floating point machinery that can kick in.

Nope, that operation is completely predictable.

Ok, so it throws away a couple of bits, of course. But then ...
there's no guarantee that different seeds will generate a
different sequence, anyway.

For your use case it might be best to use a dedicated PRNG that
isn't global like math.random(). Then you have full control over
the seeding process etc. Most PRNGs can be implemented quite
efficiently with the FFI and the 64 bit bit operations available
in LuaJIT 2.1. Or you could just call an existing C implementation
via the FFI.

--Mike

Other related posts: