8 #ifndef CVMFS_UTIL_PRNG_H_
9 #define CVMFS_UTIL_PRNG_H_
21 #ifdef CVMFS_NAMESPACE_GUARD
22 namespace CVMFS_NAMESPACE_GUARD {
40 struct timeval tv_now;
41 int retval = gettimeofday(&tv_now, NULL);
43 state_ = tv_now.tv_usec;
49 uint32_t
Next(
const uint64_t boundary) {
50 state_ = a*state_ + c;
52 static_cast<double>(state_) * static_cast<double>(boundary) /
53 static_cast<double>(18446744073709551616.0);
54 return static_cast<uint32_t
>(
static_cast<uint64_t
>(scaled_val) % boundary);
61 state_ = a*state_ + c;
62 double unit_val =
static_cast<double>(state_) /
63 static_cast<double>(18446744073709551616.0);
73 double pi = atan(1) * 4;
76 z = sqrt(-2.0 * log(u1)) * cos(2 * pi * u2);
84 static const uint64_t a = 6364136223846793005LLU;
85 static const uint64_t c = 1442695040888963407LLU;
89 #ifdef CVMFS_NAMESPACE_GUARD
93 #endif // CVMFS_UTIL_PRNG_H_
assert((mem||(size==0))&&"Out Of Memory")
void InitSeed(const uint64_t seed)
uint32_t Next(const uint64_t boundary)