| 2666 | static __thread unsigned short do_once = 0; |
| 2667 | |
| 2668 | static 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 */ |
| 2689 | static int getRandomExclude(int max, int exclude) |
no test coverage detected