67 #define __STDC_LIMIT_MACROS
70 #include <visp3/core/vpUniRand.h>
73 : m_maxInvDbl(1.0 / static_cast<double>(UINT32_MAX)), m_maxInvFlt(1.0f / static_cast<float>(UINT32_MAX)), m_rng()
86 : m_maxInvDbl(1.0 / static_cast<double>(UINT32_MAX)), m_maxInvFlt(1.0f / static_cast<float>(UINT32_MAX)), m_rng()
109 uint32_t vpUniRand::boundedRand(uint32_t bound)
125 uint32_t threshold = -bound % bound;
136 if (r >= threshold) {
148 uint64_t oldstate = m_rng.state;
149 m_rng.state = oldstate * 6364136223846793005ULL + m_rng.inc;
150 uint32_t xorshifted =
static_cast<uint32_t
>(((oldstate >> 18u) ^ oldstate) >> 27u);
151 uint32_t rot = oldstate >> 59u;
152 return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
165 return boundedRand(b - a) + a;
206 m_rng.inc = (initseq << 1u) | 1u;
208 m_rng.state += initstate;
int uniform(int a, int b)
void setSeed(uint64_t initstate, uint64_t initseq)