I have seen a lot of posts about the WELLRNG512. Supposedly I have concluded that it would be a better choice than the Mersenne Twister for a roguelike dungeon crawler. I am trying to get this piece of code to generate random numbers and behave much like rand().
Code used:
static unsigned long state[16];
static unsigned int index = 0;
int main (void) {
int i;
for (i = 0; i < 16; i++) {
index = i;
printf("random: %lu\n", WELLRNG512());
}
return 0;
}
unsigned long WELLRNG512 (void) {
unsigned long a, b, c, d;
a = state[index];
c = state[(index+13)&15];
b = a^c^(a<<16)^(c<<15);
c = state[(index+9)&15];
c ^= (c>>11);
a = state[index] = b^c;
d = a^((a<<5)&0xDA442D24UL);
index = (index + 15)&15;
a = state[index];
state[index] = a^b^d^(a<<2)^(b<<18)^(c<<28);
return state[index];
}
Expected results:
random: 231544
random: 542312
random: 588690
(...etc...)
Acquired results:
random: 4195755
random: 4195755
random: 4195755
(...etc...)
Has anyone got any idea how I can successfully make that piece of code behave like rand()?
P.S.: I'm a student, definitely not a mathematician, so please, explain your answer in great detail if you're going to use any kind of hieroglyphs to explain formula's, etc.