45 lines
740 B
C
45 lines
740 B
C
|
#include "stdafx.h"
|
||
|
#include "Random.h"
|
||
|
|
||
|
/* From https://prng.di.unimi.it/xoshiro256plusplus.c */
|
||
|
|
||
|
static UINT64 s[4];
|
||
|
|
||
|
static __inline UINT64
|
||
|
rotl(const UINT64 x, int k)
|
||
|
{
|
||
|
return (x << k) | (x >> (64 - k));
|
||
|
}
|
||
|
|
||
|
void
|
||
|
xorsrand(unsigned int seed)
|
||
|
{
|
||
|
UINT64 x = seed;
|
||
|
int i;
|
||
|
|
||
|
for (i = 0; i < 4; i++) {
|
||
|
UINT64 z = (x += 0x9E3779B97F4A7C15ULL);
|
||
|
z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ULL;
|
||
|
z = (z ^ (z >> 27)) * 0x94D049BB133111EBULL;
|
||
|
s[i] = x = z ^ (z >> 31);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
UINT64
|
||
|
xorrand(void)
|
||
|
{
|
||
|
const UINT64 result = rotl(s[0] + s[3], 23) + s[0];
|
||
|
|
||
|
const UINT64 t = s[1] << 17;
|
||
|
|
||
|
s[2] ^= s[0];
|
||
|
s[3] ^= s[1];
|
||
|
s[1] ^= s[2];
|
||
|
s[0] ^= s[3];
|
||
|
|
||
|
s[2] ^= t;
|
||
|
|
||
|
s[3] = rotl(s[3], 45);
|
||
|
|
||
|
return result;
|
||
|
}
|