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

Function rk_random_bool

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

* Fills an array with cnt random npy_bool between off and off + rng * inclusive. */

Source from the content-addressed store, hash-verified

408 * inclusive.
409 */
410void rk_random_bool(npy_bool off, npy_bool rng, npy_intp cnt, npy_bool *out,
411 rk_state *state) {
412 npy_intp i;
413 npy_uint32 buf;
414 int bcnt = 0;
415
416 if (rng == 0) {
417 for (i = 0; i < cnt; i++) {
418 out[i] = off;
419 }
420 return;
421 }
422
423 /* If we reach here rng and mask are one and off is zero */
424 assert(rng == 1 && off == 0);
425 for (i = 0; i < cnt; i++) {
426 if (!bcnt) {
427 buf = rk_uint32(state);
428 bcnt = 31;
429 } else {
430 buf >>= 1;
431 bcnt--;
432 }
433 out[i] = (buf & 0x00000001) != 0;
434 }
435}
436
437long rk_long(rk_state *state) { return rk_ulong(state) >> 1; }
438

Callers

nothing calls this directly

Calls 1

rk_uint32Function · 0.85

Tested by

no test coverage detected