Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
Fast randomness source. More...
#include <random.h>
Public Member Functions | |
FastRandomContext (bool fDeterministic=false) | |
FastRandomContext (const uint256 &seed) | |
Initialize with explicit seed (only for testing) More... | |
uint64_t | rand64 () |
Generate a random 64-bit integer. More... | |
uint64_t | randbits (int bits) |
Generate a random (bits)-bit integer. More... | |
uint64_t | randrange (uint64_t range) |
Generate a random integer in the range [0..range). More... | |
uint32_t | rand32 (uint32_t nMax) |
uint32_t | operator() (uint32_t nMax) |
std::vector< unsigned char > | randbytes (size_t len) |
Generate random bytes. More... | |
uint32_t | rand32 () |
Generate a random 32-bit integer. More... | |
uint256 | rand256 () |
generate a random uint256. More... | |
bool | randbool () |
Generate a random boolean. More... | |
Private Member Functions | |
void | RandomSeed () |
void | FillByteBuffer () |
void | FillBitBuffer () |
Private Attributes | |
bool | requires_seed |
ChaCha20 | rng |
unsigned char | bytebuf [64] |
int | bytebuf_size |
uint64_t | bitbuf |
int | bitbuf_size |
Detailed Description
Fast randomness source.
This is seeded once with secure random data, but is completely deterministic and insecure after that. This class is not thread-safe.
Constructor & Destructor Documentation
◆ FastRandomContext() [1/2]
|
explicit |
Definition at line 478 of file random.cpp.
References base_blob< BITS >::begin(), rng, and ChaCha20::SetKey().
◆ FastRandomContext() [2/2]
|
explicit |
Initialize with explicit seed (only for testing)
Definition at line 429 of file random.cpp.
References base_blob< BITS >::begin(), rng, and ChaCha20::SetKey().
Member Function Documentation
◆ FillBitBuffer()
|
inlineprivate |
Definition at line 70 of file random.h.
References bitbuf, bitbuf_size, and rand64().
Referenced by randbits().
◆ FillByteBuffer()
|
inlineprivate |
Definition at line 61 of file random.h.
References bytebuf, bytebuf_size, ChaCha20::Keystream(), RandomSeed(), requires_seed, and rng.
◆ operator()()
|
inline |
◆ rand256()
uint256 FastRandomContext::rand256 | ( | ) |
generate a random uint256.
Definition at line 409 of file random.cpp.
References base_blob< BITS >::begin(), bytebuf, bytebuf_size, FillByteBuffer(), and memcpy().
Referenced by MerkleRoot().
◆ rand32() [1/2]
|
inline |
◆ rand32() [2/2]
|
inline |
Generate a random 32-bit integer.
Definition at line 129 of file random.h.
References randbits().
Referenced by operator()(), and rand32().
◆ rand64()
|
inline |
Generate a random 64-bit integer.
Definition at line 83 of file random.h.
References bytebuf, bytebuf_size, FillByteBuffer(), and ReadLE64().
Referenced by FillBitBuffer(), and randbits().
◆ randbits()
|
inline |
Generate a random (bits)-bit integer.
Definition at line 92 of file random.h.
References bitbuf, bitbuf_size, immer::detail::rbts::bits, FillBitBuffer(), and rand64().
Referenced by rand32(), randbool(), randrange(), and CAddrMan::Select_().
◆ randbool()
|
inline |
Generate a random boolean.
Definition at line 135 of file random.h.
References randbits().
Referenced by ApproximateBestSubset(), and FastRandom_1bit().
◆ randbytes()
std::vector< unsigned char > FastRandomContext::randbytes | ( | size_t | len | ) |
Generate random bytes.
Definition at line 420 of file random.cpp.
References ChaCha20::Keystream(), and rng.
◆ RandomSeed()
|
private |
Definition at line 402 of file random.cpp.
References base_blob< BITS >::begin(), GetRandHash(), requires_seed, rng, and ChaCha20::SetKey().
Referenced by FillByteBuffer().
◆ randrange()
|
inline |
Generate a random integer in the range [0..range).
Definition at line 107 of file random.h.
References immer::detail::rbts::bits, CountBits(), and randbits().
Referenced by CCoinsViewDB::BatchWrite(), CCheckQueueSpeedPrevectorJob(), GetRand(), and CNode::PushAddress().
Member Data Documentation
◆ bitbuf
|
private |
Definition at line 56 of file random.h.
Referenced by FillBitBuffer(), and randbits().
◆ bitbuf_size
|
private |
Definition at line 57 of file random.h.
Referenced by FillBitBuffer(), and randbits().
◆ bytebuf
|
private |
Definition at line 53 of file random.h.
Referenced by FillByteBuffer(), rand256(), and rand64().
◆ bytebuf_size
|
private |
Definition at line 54 of file random.h.
Referenced by FillByteBuffer(), rand256(), and rand64().
◆ requires_seed
|
private |
Definition at line 50 of file random.h.
Referenced by FillByteBuffer(), and RandomSeed().
◆ rng
|
private |
Definition at line 51 of file random.h.
Referenced by FastRandomContext(), FillByteBuffer(), randbytes(), and RandomSeed().
The documentation for this class was generated from the following files:
- src/random.h
- src/random.cpp