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

Function random_bounded_uint32_fill

numpy/random/src/distributions/distributions.c:1573–1605  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1571 * inclusive. The numbers wrap if rng is sufficiently large.
1572 */
1573void random_bounded_uint32_fill(bitgen_t *bitgen_state, uint32_t off,
1574 uint32_t rng, npy_intp cnt, bool use_masked,
1575 uint32_t *out) {
1576 npy_intp i;
1577 uint32_t buf = 0;
1578 int bcnt = 0;
1579
1580 if (rng == 0) {
1581 for (i = 0; i < cnt; i++) {
1582 out[i] = off;
1583 }
1584 } else if (rng == 0xFFFFFFFFUL) {
1585 /* Lemire32 doesn't support rng = 0xFFFFFFFF. */
1586 for (i = 0; i < cnt; i++) {
1587 out[i] = off + next_uint32(bitgen_state);
1588 }
1589 } else {
1590 if (use_masked) {
1591 /* Smallest bit mask >= max */
1592 uint32_t mask = (uint32_t)gen_mask(rng);
1593
1594 for (i = 0; i < cnt; i++) {
1595 out[i] = off + buffered_bounded_masked_uint32(bitgen_state, rng, mask,
1596 &bcnt, &buf);
1597 }
1598 } else {
1599 for (i = 0; i < cnt; i++) {
1600 out[i] = off +
1601 buffered_bounded_lemire_uint32(bitgen_state, rng, &bcnt, &buf);
1602 }
1603 }
1604 }
1605}
1606
1607/*
1608 * Fills an array with cnt random npy_uint16 between off and off + rng

Callers

nothing calls this directly

Calls 4

next_uint32Function · 0.85
gen_maskFunction · 0.85

Tested by

no test coverage detected