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

Method randbits

src/random.h:184–197  ·  view source on GitHub ↗

Generate a random (bits)-bit integer. */

Source from the content-addressed store, hash-verified

182
183 /** Generate a random (bits)-bit integer. */
184 uint64_t randbits(int bits) noexcept
185 {
186 if (bits == 0) {
187 return 0;
188 } else if (bits > 32) {
189 return rand64() >> (64 - bits);
190 } else {
191 if (bitbuf_size < bits) FillBitBuffer();
192 uint64_t ret = bitbuf & (~(uint64_t)0 >> (64 - bits));
193 bitbuf >>= bits;
194 bitbuf_size -= bits;
195 return ret;
196 }
197 }
198
199 /** Generate a random integer in the range [0..range).
200 * Precondition: range > 0.

Callers 7

Select_Method · 0.80
GetLocalAddrForPeerFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
AddRandomOutboundPeerFunction · 0.80
FUZZ_TARGETFunction · 0.80
InsecureRandBitsFunction · 0.80

Calls

no outgoing calls

Tested by 5

BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
AddRandomOutboundPeerFunction · 0.64
FUZZ_TARGETFunction · 0.64
InsecureRandBitsFunction · 0.64