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

Function random_bounded_uint8_fill

numpy/random/src/distributions/distributions.c:1649–1680  ·  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

1647 * inclusive. The numbers wrap if rng is sufficiently large.
1648 */
1649void random_bounded_uint8_fill(bitgen_t *bitgen_state, uint8_t off, uint8_t rng,
1650 npy_intp cnt, bool use_masked, uint8_t *out) {
1651 npy_intp i;
1652 uint32_t buf = 0;
1653 int bcnt = 0;
1654
1655 if (rng == 0) {
1656 for (i = 0; i < cnt; i++) {
1657 out[i] = off;
1658 }
1659 } else if (rng == 0xFFUL) {
1660 /* Lemire8 doesn't support rng = 0xFF. */
1661 for (i = 0; i < cnt; i++) {
1662 out[i] = off + buffered_uint8(bitgen_state, &bcnt, &buf);
1663 }
1664 } else {
1665 if (use_masked) {
1666 /* Smallest bit mask >= max */
1667 uint8_t mask = (uint8_t)gen_mask(rng);
1668
1669 for (i = 0; i < cnt; i++) {
1670 out[i] = off + buffered_bounded_masked_uint8(bitgen_state, rng, mask,
1671 &bcnt, &buf);
1672 }
1673 } else {
1674 for (i = 0; i < cnt; i++) {
1675 out[i] =
1676 off + buffered_bounded_lemire_uint8(bitgen_state, rng, &bcnt, &buf);
1677 }
1678 }
1679 }
1680}
1681
1682/*
1683 * Fills an array with cnt random npy_bool between off and off + rng

Callers

nothing calls this directly

Calls 4

buffered_uint8Function · 0.85
gen_maskFunction · 0.85

Tested by

no test coverage detected