Xorshift Generation
suggest changeA good and easy alternative to the flawed rand()
procedures, is xorshift, a class of pseudo-random number generators discovered by George Marsaglia. The xorshift generator is among the fastest non-cryptographically-secure random number generators. More information and other example implementaions are available on the xorshift Wikipedia page
Example implementation
#include <stdint.h> /* These state variables must be initialised so that they are not all zero. */ uint32_t w, x, y, z; uint32_t xorshift128(void) { uint32_t t = x; t ^= t << 11U; t ^= t >> 8U; x = y; y = z; z = w; w ^= w >> 19U; w ^= t; return w; }
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents