MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / cdb2_random_int

Function cdb2_random_int

cdb2api/cdb2api.c:2668–2686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2666static __thread unsigned short do_once = 0;
2667
2668static int cdb2_random_int()
2669{
2670 if (!do_once) {
2671 struct timeval tv;
2672 gettimeofday(&tv, NULL);
2673 /* Initialize rand_state once per thread
2674 * _PID will ensure that cnonce will be different accross processes
2675 * Get the initial random state by using thread id and time info. */
2676 uint32_t tmp[2];
2677 tmp[0] = tv.tv_sec;
2678 tmp[1] = tv.tv_usec;
2679 uint64_t hash = val_combine(*(uint64_t *)tmp, (uint64_t)pthread_self());
2680 rand_state[0] = hash;
2681 rand_state[1] = hash >> 16;
2682 rand_state[2] = hash >> 32;
2683 do_once = 1;
2684 }
2685 return nrand48(rand_state);
2686}
2687
2688/* Get random value from range 0 to max-1 excluding 1 value */
2689static int getRandomExclude(int max, int exclude)

Callers 1

getRandomExcludeFunction · 0.85

Calls 1

val_combineFunction · 0.85

Tested by

no test coverage detected