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

Function rk_random_uint8

numpy/random/src/mt19937/randomkit.c:372–404  ·  view source on GitHub ↗

* Fills an array with cnt random npy_uint8 between off and off + rng * inclusive. The numbers wrap if rng is sufficiently large. */

Source from the content-addressed store, hash-verified

370 * inclusive. The numbers wrap if rng is sufficiently large.
371 */
372void rk_random_uint8(npy_uint8 off, npy_uint8 rng, npy_intp cnt, npy_uint8 *out,
373 rk_state *state) {
374 npy_uint8 val, mask = rng;
375 npy_intp i;
376 npy_uint32 buf;
377 int bcnt = 0;
378
379 if (rng == 0) {
380 for (i = 0; i < cnt; i++) {
381 out[i] = off;
382 }
383 return;
384 }
385
386 /* Smallest bit mask >= max */
387 mask |= mask >> 1;
388 mask |= mask >> 2;
389 mask |= mask >> 4;
390
391 for (i = 0; i < cnt; i++) {
392 do {
393 if (!bcnt) {
394 buf = rk_uint32(state);
395 bcnt = 3;
396 } else {
397 buf >>= 8;
398 bcnt--;
399 }
400 val = (npy_uint8)buf & mask;
401 } while (val > rng);
402 out[i] = off + val;
403 }
404}
405
406/*
407 * Fills an array with cnt random npy_bool between off and off + rng

Callers

nothing calls this directly

Calls 1

rk_uint32Function · 0.85

Tested by

no test coverage detected