// Bob Jenkins small PRNG in C++ templates (all compile time) // see original public domain implementation in C // http://burtleburtle.net/bob/rand/smallprng.html // http://burtleburtle.net/bob/rand/talksmall.html (for license) // // This is put in the public domain by me personally // Dale Weiler // // to use: Rotate::value // cycle is the call count, i.e using 0 as cycle is the same as calling the C version once // 1 would be twice, 2 .. would be 3 times, etc, etc template struct Rotate { enum { value = ((x << y) | (x >> (32 - y))) }; }; template struct Context; template struct Context<0, S> { enum { a = 0xF1EA5EED, b = S, c = S, d = S }; }; template struct Context { enum { e = Context::a - Rotate::b, 27>::value, a = Context::b ^ Rotate::c, 17>::value, b = Context::c + Context::d, c = Context::d + e, d = e + a, }; }; template struct Random { enum { value = Context<21 + cycle, S>::d }; };