* Fills an array with cnt random npy_uint16 between off and off + rng * inclusive. The numbers wrap if rng is sufficiently large. */
| 331 | * inclusive. The numbers wrap if rng is sufficiently large. |
| 332 | */ |
| 333 | void rk_random_uint16(npy_uint16 off, npy_uint16 rng, npy_intp cnt, |
| 334 | npy_uint16 *out, rk_state *state) { |
| 335 | npy_uint16 val, mask = rng; |
| 336 | npy_intp i; |
| 337 | npy_uint32 buf; |
| 338 | int bcnt = 0; |
| 339 | |
| 340 | if (rng == 0) { |
| 341 | for (i = 0; i < cnt; i++) { |
| 342 | out[i] = off; |
| 343 | } |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | /* Smallest bit mask >= max */ |
| 348 | mask |= mask >> 1; |
| 349 | mask |= mask >> 2; |
| 350 | mask |= mask >> 4; |
| 351 | mask |= mask >> 8; |
| 352 | |
| 353 | for (i = 0; i < cnt; i++) { |
| 354 | do { |
| 355 | if (!bcnt) { |
| 356 | buf = rk_uint32(state); |
| 357 | bcnt = 1; |
| 358 | } else { |
| 359 | buf >>= 16; |
| 360 | bcnt--; |
| 361 | } |
| 362 | val = (npy_uint16)buf & mask; |
| 363 | } while (val > rng); |
| 364 | out[i] = off + val; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Fills an array with cnt random npy_uint8 between off and off + rng |
nothing calls this directly
no test coverage detected