use mrand in baground
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "values/mrand.hpp"
|
||||
|
||||
static uint32_t rprand_state[4] = {0};
|
||||
static uint64_t rprand_seed = 0;
|
||||
|
||||
static inline uint32_t my_rotate_left(const uint32_t x, int k)
|
||||
{
|
||||
@@ -27,7 +26,7 @@ uint32_t my_rprand_xoshiro(uint32_t state[4])
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t rprand_splitmix64()
|
||||
uint64_t rprand_splitmix64(uint64_t &rprand_seed)
|
||||
{
|
||||
uint64_t z = (rprand_seed += 0x9e3779b97f4a7c15);
|
||||
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
@@ -39,14 +38,14 @@ namespace mrand
|
||||
{
|
||||
void setSeed(unsigned long long seed)
|
||||
{
|
||||
rprand_seed = (uint64_t)seed; // Set SplitMix64 seed for further use
|
||||
uint64_t rprand_seed = (uint64_t)seed; // Set SplitMix64 seed for further use
|
||||
|
||||
// To generate the Xoshiro128** state, we use SplitMix64 generator first
|
||||
// We generate 4 pseudo-random 64bit numbers that we combine using their LSB|MSB
|
||||
rprand_state[0] = (uint32_t)(rprand_splitmix64() & 0xffffffff);
|
||||
rprand_state[1] = (uint32_t)((rprand_splitmix64() & 0xffffffff00000000) >> 32);
|
||||
rprand_state[2] = (uint32_t)(rprand_splitmix64() & 0xffffffff);
|
||||
rprand_state[3] = (uint32_t)((rprand_splitmix64() & 0xffffffff00000000) >> 32);
|
||||
rprand_state[0] = (uint32_t)(rprand_splitmix64(rprand_seed) & 0xffffffff);
|
||||
rprand_state[1] = (uint32_t)((rprand_splitmix64(rprand_seed) & 0xffffffff00000000) >> 32);
|
||||
rprand_state[2] = (uint32_t)(rprand_splitmix64(rprand_seed) & 0xffffffff);
|
||||
rprand_state[3] = (uint32_t)((rprand_splitmix64(rprand_seed) & 0xffffffff00000000) >> 32);
|
||||
}
|
||||
|
||||
int getValue(int min, int max)
|
||||
@@ -60,4 +59,16 @@ namespace mrand
|
||||
{
|
||||
return my_rprand_xoshiro(rprand_state) / 4294967295.0f;
|
||||
}
|
||||
|
||||
int getValue(int min, int max, uint32_t state[4])
|
||||
{
|
||||
int value = my_rprand_xoshiro(state) % (std::abs(max - min) + 1) + min;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
float getFloat(uint32_t state[4])
|
||||
{
|
||||
return my_rprand_xoshiro(state) / 4294967295.0f;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user