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

Function random_bounded_uint64_fill

numpy/random/src/distributions/distributions.c:1508–1567  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1506 * inclusive. The numbers wrap if rng is sufficiently large.
1507 */
1508void random_bounded_uint64_fill(bitgen_t *bitgen_state, uint64_t off,
1509 uint64_t rng, npy_intp cnt, bool use_masked,
1510 uint64_t *out) {
1511 npy_intp i;
1512
1513 if (rng == 0) {
1514 for (i = 0; i < cnt; i++) {
1515 out[i] = off;
1516 }
1517 } else if (rng <= 0xFFFFFFFFUL) {
1518 /* Call 32-bit generator if range in 32-bit. */
1519
1520 /*
1521 * The 32-bit Lemire method does not handle rng=0xFFFFFFFF, so we'll
1522 * call next_uint32 directly. This also works when use_masked is True,
1523 * so we handle both cases here.
1524 */
1525 if (rng == 0xFFFFFFFFUL) {
1526 for (i = 0; i < cnt; i++) {
1527 out[i] = off + (uint64_t) next_uint32(bitgen_state);
1528 }
1529 } else {
1530 uint32_t buf = 0;
1531 int bcnt = 0;
1532
1533 if (use_masked) {
1534 /* Smallest bit mask >= max */
1535 uint64_t mask = gen_mask(rng);
1536
1537 for (i = 0; i < cnt; i++) {
1538 out[i] = off + buffered_bounded_masked_uint32(bitgen_state, rng, mask,
1539 &bcnt, &buf);
1540 }
1541 } else {
1542 for (i = 0; i < cnt; i++) {
1543 out[i] = off +
1544 buffered_bounded_lemire_uint32(bitgen_state, rng, &bcnt, &buf);
1545 }
1546 }
1547 }
1548 } else if (rng == 0xFFFFFFFFFFFFFFFFULL) {
1549 /* Lemire64 doesn't support rng = 0xFFFFFFFFFFFFFFFF. */
1550 for (i = 0; i < cnt; i++) {
1551 out[i] = off + next_uint64(bitgen_state);
1552 }
1553 } else {
1554 if (use_masked) {
1555 /* Smallest bit mask >= max */
1556 uint64_t mask = gen_mask(rng);
1557
1558 for (i = 0; i < cnt; i++) {
1559 out[i] = off + bounded_masked_uint64(bitgen_state, rng, mask);
1560 }
1561 } else {
1562 for (i = 0; i < cnt; i++) {
1563 out[i] = off + bounded_lemire_uint64(bitgen_state, rng);
1564 }
1565 }

Callers

nothing calls this directly

Calls 7

next_uint32Function · 0.85
gen_maskFunction · 0.85
next_uint64Function · 0.85
bounded_masked_uint64Function · 0.85
bounded_lemire_uint64Function · 0.85

Tested by

no test coverage detected