#include "core/core.h"

class PRNG
{
public:
	u64 keys[4];							// 4 keys

	static inline u64 rol( u64 r, int amt )
	{
		return (r << amt) | (r >> (64-amt) );
	}
	static inline u64 ror( u64 r, int amt )
	{
		return (r >> amt) | (r << (64-amt) );
	}

	// passes diehard tests!
	// can't test dieharder under windows
	// one round of PRNG
	inline u64 rand64()
	{
		u64 tmp = keys[0] + keys[2] - keys[1] - keys[3];
		keys[0] ^= rol( keys[1], 5 );
		keys[1] += ror( keys[2], 27 );
		keys[2] -= rol( keys[3], 41 );
		return keys[3] ^= ror( tmp, 17 ) - 0xfacebabec0ca101aULL;
	}

	inline PRNG()
	{
		keys[0] = keys[1] = keys[2] = keys[3] = 0;
		// scramble
		int i;
		for (i=0; i<64; i++)
		{
			rand64();
		}
	}
};
