lua-users home
lua-l archive

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


seeding the random generator can possibly be simpler (without warm-up)

http://xoroshiro.di.unimi.it/, section "Why just sizes 128 and 1024":

For 64 bits, we suggest to use a SplitMix64 generator, but 64 bits of state are 
not enough for any serious purpose. Nonetheless, SplitMix64 is very useful to 
initialize the state of other generators starting from a 64-bit seed, as research 
has shown that initialization must be performed with a generator radically different 
in nature from the one initialized to avoid correlation on similar seeds.

---

I tried a simpler approach, using Knuth MMIX LCG:

#define LCG(x)   (6364136223846793005ULL * (x) + 1442695040888963407ULL)

static void setseed (I *state, lua_Integer n) {
  state[0] = Int2I(n);           // guaranteed not stuck in zero state,
  state[1] = LCG(Int2I(n)); // and state[0], state[1] very different 
}