Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

Fast randomness source. More...

#include <random.h>

+ Collaboration diagram for FastRandomContext:

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.

Definition at line 48 of file random.h.

Constructor & Destructor Documentation

◆ FastRandomContext() [1/2]

FastRandomContext::FastRandomContext ( bool  fDeterministic = false)
explicit

Definition at line 478 of file random.cpp.

References base_blob< BITS >::begin(), rng, and ChaCha20::SetKey().

◆ FastRandomContext() [2/2]

FastRandomContext::FastRandomContext ( const uint256 seed)
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()

void FastRandomContext::FillBitBuffer ( )
inlineprivate

Definition at line 70 of file random.h.

References bitbuf, bitbuf_size, and rand64().

Referenced by randbits().

◆ FillByteBuffer()

void FastRandomContext::FillByteBuffer ( )
inlineprivate

Definition at line 61 of file random.h.

References bytebuf, bytebuf_size, ChaCha20::Keystream(), RandomSeed(), requires_seed, and rng.

Referenced by rand256(), and rand64().

◆ operator()()

uint32_t FastRandomContext::operator() ( uint32_t  nMax)
inline

Definition at line 121 of file random.h.

References rand32().

◆ 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]

uint32_t FastRandomContext::rand32 ( uint32_t  nMax)
inline

Definition at line 117 of file random.h.

References rand32().

Referenced by FastRandom_32bit().

◆ rand32() [2/2]

uint32_t FastRandomContext::rand32 ( )
inline

Generate a random 32-bit integer.

Definition at line 129 of file random.h.

References randbits().

Referenced by operator()(), and rand32().

◆ rand64()

uint64_t FastRandomContext::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()

uint64_t FastRandomContext::randbits ( int  bits)
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()

bool FastRandomContext::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()

void FastRandomContext::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()

uint64_t FastRandomContext::randrange ( uint64_t  range)
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

uint64_t FastRandomContext::bitbuf
private

Definition at line 56 of file random.h.

Referenced by FillBitBuffer(), and randbits().

◆ bitbuf_size

int FastRandomContext::bitbuf_size
private

Definition at line 57 of file random.h.

Referenced by FillBitBuffer(), and randbits().

◆ bytebuf

unsigned char FastRandomContext::bytebuf[64]
private

Definition at line 53 of file random.h.

Referenced by FillByteBuffer(), rand256(), and rand64().

◆ bytebuf_size

int FastRandomContext::bytebuf_size
private

Definition at line 54 of file random.h.

Referenced by FillByteBuffer(), rand256(), and rand64().

◆ requires_seed

bool FastRandomContext::requires_seed
private

Definition at line 50 of file random.h.

Referenced by FillByteBuffer(), and RandomSeed().

◆ rng

ChaCha20 FastRandomContext::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:
Released under the MIT license