This Wikipedia article, for example, presents a simple RNG using only xor and shift:
/* The state word must be initialized to non-zero */
uint32_t xorshift32(uint32_t state[static 1])
{
/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
uint32_t x = state[0];
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
state[0] = x;
return x;
}
Note the shift operations here fill removed bits with 0. Is there any RNG that uses cyclic shifts instead (i.e., ones that bits loop around)?
Aucun commentaire:
Enregistrer un commentaire