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

Function random_bounded_uint16_fill

numpy/random/src/distributions/distributions.c:1611–1643  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1609 * inclusive. The numbers wrap if rng is sufficiently large.
1610 */
1611void random_bounded_uint16_fill(bitgen_t *bitgen_state, uint16_t off,
1612 uint16_t rng, npy_intp cnt, bool use_masked,
1613 uint16_t *out) {
1614 npy_intp i;
1615 uint32_t buf = 0;
1616 int bcnt = 0;
1617
1618 if (rng == 0) {
1619 for (i = 0; i < cnt; i++) {
1620 out[i] = off;
1621 }
1622 } else if (rng == 0xFFFFUL) {
1623 /* Lemire16 doesn't support rng = 0xFFFF. */
1624 for (i = 0; i < cnt; i++) {
1625 out[i] = off + buffered_uint16(bitgen_state, &bcnt, &buf);
1626 }
1627 } else {
1628 if (use_masked) {
1629 /* Smallest bit mask >= max */
1630 uint16_t mask = (uint16_t)gen_mask(rng);
1631
1632 for (i = 0; i < cnt; i++) {
1633 out[i] = off + buffered_bounded_masked_uint16(bitgen_state, rng, mask,
1634 &bcnt, &buf);
1635 }
1636 } else {
1637 for (i = 0; i < cnt; i++) {
1638 out[i] = off +
1639 buffered_bounded_lemire_uint16(bitgen_state, rng, &bcnt, &buf);
1640 }
1641 }
1642 }
1643}
1644
1645/*
1646 * Fills an array with cnt random npy_uint8 between off and off + rng

Callers

nothing calls this directly

Calls 4

buffered_uint16Function · 0.85
gen_maskFunction · 0.85

Tested by

no test coverage detected