I need a 32 and 64 bit PRNG and have decided to use LCG. Most implementations are either:
X = (aX + c) mod m or
X = (aX + c) and m
But is the m really necessary? If my X is a uint32 and uint64 respectively wouldn't the data type handle any wrapping for me automatically without me having to explicitly use a mod or an and? As per my implementation below.
#ifdef X32
uint32 state = seed;
uint32 a = 1103515245;
uint32 c = 12345;
#else
uint64 state = seed;
uint64 a = 2862933555777941757;
uint64 c = 3037000493;
#endif
state = a * state + c;
Aucun commentaire:
Enregistrer un commentaire