MCPcopy Create free account
hub / github.com/ElementsProject/elements / randrange

Method randrange

src/random.h:202–211  ·  view source on GitHub ↗

Generate a random integer in the range [0..range). * Precondition: range > 0. */

Source from the content-addressed store, hash-verified

200 * Precondition: range > 0.
201 */
202 uint64_t randrange(uint64_t range) noexcept
203 {
204 assert(range);
205 --range;
206 int bits = CountBits(range);
207 while (true) {
208 uint64_t ret = randbits(bits);
209 if (ret <= range) return ret;
210 }
211 }
212
213 /** Generate random bytes. */
214 std::vector<unsigned char> randbytes(size_t len);

Callers 15

transact_and_mineMethod · 0.80
setup_addr_msgMethod · 0.80
rand_keysMethod · 0.80
do_test_sendtoaddressMethod · 0.80
do_test_psbtMethod · 0.80
transact_and_mineMethod · 0.80
fnFunction · 0.80
spenders_taproot_activeFunction · 0.80
test_spendersMethod · 0.80
setupMethod · 0.80
generate_privkeyFunction · 0.80

Calls 1

CountBitsFunction · 0.50

Tested by 14

test_spendersMethod · 0.64
setupMethod · 0.64
test_schnorrMethod · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
FUZZ_TARGETFunction · 0.64
RandAddrFunction · 0.64
FillAddrmanFunction · 0.64