* Fills an array with cnt random npy_uint32 between off and off + rng * inclusive. The numbers wrap if rng is sufficiently large. */
| 301 | * inclusive. The numbers wrap if rng is sufficiently large. |
| 302 | */ |
| 303 | void rk_random_uint32(npy_uint32 off, npy_uint32 rng, npy_intp cnt, |
| 304 | npy_uint32 *out, rk_state *state) { |
| 305 | npy_uint32 val, mask = rng; |
| 306 | npy_intp i; |
| 307 | |
| 308 | if (rng == 0) { |
| 309 | for (i = 0; i < cnt; i++) { |
| 310 | out[i] = off; |
| 311 | } |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | /* Smallest bit mask >= max */ |
| 316 | mask |= mask >> 1; |
| 317 | mask |= mask >> 2; |
| 318 | mask |= mask >> 4; |
| 319 | mask |= mask >> 8; |
| 320 | mask |= mask >> 16; |
| 321 | |
| 322 | for (i = 0; i < cnt; i++) { |
| 323 | while ((val = (rk_uint32(state) & mask)) > rng) |
| 324 | ; |
| 325 | out[i] = off + val; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Fills an array with cnt random npy_uint16 between off and off + rng |
nothing calls this directly
no test coverage detected