我有一个 RNG 函数xorshift128plus需要一个Xorshift128PlusKey:
/**
* \brief Keys for scalar xorshift128. Must be non-zero.
* These are modified by xorshift128plus.
*/
struct Xorshift128PlusKey
{
uint64_t s1;
uint64_t s2;
};
/**
* \brief Return a new 64-bit random number.
*/
uint64_t xorshift128plus(Xorshift128PlusKey* key);
我想使用rdtsc(处理器时间戳)播种我的 RNG。问题是__rdtsc
msvc 下的内在函数返回一个64 位无符号整数,而种子必须是一个32 位无符号整数。在保留随机性的同时将 rdtsc 转换为种子的最佳方法是什么。转换必须尽可能快。
我不能使用std lib或boost。(用于游戏引擎)