MCPcopy Create free account
hub / github.com/numpy/numpy / random_interval

Function random_interval

numpy/random/src/distributions/distributions.c:1048–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046
1047
1048uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max) {
1049 uint64_t mask, value;
1050 if (max == 0) {
1051 return 0;
1052 }
1053
1054 mask = max;
1055
1056 /* Smallest bit mask >= max */
1057 mask |= mask >> 1;
1058 mask |= mask >> 2;
1059 mask |= mask >> 4;
1060 mask |= mask >> 8;
1061 mask |= mask >> 16;
1062 mask |= mask >> 32;
1063
1064 /* Search a random value in [0..mask] <= max */
1065 if (max <= 0xffffffffUL) {
1066 while ((value = (next_uint32(bitgen_state) & mask)) > max)
1067 ;
1068 } else {
1069 while ((value = (next_uint64(bitgen_state) & mask)) > max)
1070 ;
1071 }
1072 return value;
1073}
1074
1075/* Bounded generators */
1076static inline uint64_t gen_mask(uint64_t max) {

Callers 2

hypergeometric_sampleFunction · 0.85

Calls 2

next_uint32Function · 0.85
next_uint64Function · 0.85

Tested by

no test coverage detected