I came across this pseudo random number generator, Jenkins JSF, or Jenkins small fast prng, and attempted to translate the C to XBLite. But I have not had any success in getting it to work. I have my attempt attached.
Maybe someone else can figure out what is needed to make this work.
typedef uint32_t u4;
typedef struct ranctx { u4 a; u4 b; u4 c; u4 d; } ranctx;
#define rot32(x,k) (((x)<<(k))|((x)>>(32-(k))))
u4 ranval( ranctx *x ) {
u4 e = x->a - rot32(x->b, 27);
x->a = x->b ^ rot32(x->c, 17);
x->b = x->c + x->d;
x->c = x->d + e;
x->d = e + x->a;
return x->d;
}
void raninit( ranctx *x, u4 seed ) {
u4 i;
x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
for (i=0; i<20; ++i) {
(void)ranval(x);
}
}
The C code for the 32-bit variant is also included in my program file. If we can get this figured out, there is also a 64-bit variant as well. Although, after looking at the code for the 64-bit prng, it uses a integer type of uint64_t which is an unsigned 8 byte type. Our GIANT type is signed 8 bytes, so it may be a problem doing the 64-bit one.
Here is the 64-bit C for JSF:
typedef uint64_t u8;
typedef struct ranctx { u8 a; u8 b; u8 c; u8 d; } ranctx;
#define rot64(x,k) (((x)<<(k))|((x)>>(64-(k))))
u8 ranval( ranctx *x ) {
u8 e = x->a - rot64(x->b, 7);
x->a = x->b ^ rot64(x->c, 13);
x->b = x->c + rot64(x->d, 37);
x->c = x->d + e;
x->d = e + x->a;
return x->d;
}
void raninit( ranctx *x, u8 seed ) {
u8 i;
x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
for (i=0; i<20; ++i) {
(void)ranval(x);
}
}