* Returns a single random npy_uint64 between off and off + rng * inclusive. The numbers wrap if rng is sufficiently large. */
| 1389 | * inclusive. The numbers wrap if rng is sufficiently large. |
| 1390 | */ |
| 1391 | uint64_t random_bounded_uint64(bitgen_t *bitgen_state, uint64_t off, |
| 1392 | uint64_t rng, uint64_t mask, bool use_masked) { |
| 1393 | if (rng == 0) { |
| 1394 | return off; |
| 1395 | } else if (rng <= 0xFFFFFFFFUL) { |
| 1396 | /* Call 32-bit generator if range in 32-bit. */ |
| 1397 | if (rng == 0xFFFFFFFFUL) { |
| 1398 | /* |
| 1399 | * The 32-bit Lemire method does not handle rng=0xFFFFFFFF, so we'll |
| 1400 | * call next_uint32 directly. This also works when use_masked is True, |
| 1401 | * so we handle both cases here. |
| 1402 | */ |
| 1403 | return off + (uint64_t) next_uint32(bitgen_state); |
| 1404 | } |
| 1405 | if (use_masked) { |
| 1406 | return off + buffered_bounded_masked_uint32(bitgen_state, rng, mask, NULL, |
| 1407 | NULL); |
| 1408 | } else { |
| 1409 | return off + |
| 1410 | buffered_bounded_lemire_uint32(bitgen_state, rng, NULL, NULL); |
| 1411 | } |
| 1412 | } else if (rng == 0xFFFFFFFFFFFFFFFFULL) { |
| 1413 | /* Lemire64 doesn't support inclusive rng = 0xFFFFFFFFFFFFFFFF. */ |
| 1414 | return off + next_uint64(bitgen_state); |
| 1415 | } else { |
| 1416 | if (use_masked) { |
| 1417 | return off + bounded_masked_uint64(bitgen_state, rng, mask); |
| 1418 | } else { |
| 1419 | return off + bounded_lemire_uint64(bitgen_state, rng); |
| 1420 | } |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * Returns a single random npy_uint64 between off and off + rng |
nothing calls this directly
no test coverage detected