Bitcoin Core  0.15.99
P2P Digital Currency
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FastRandomContext Class Reference

Fast randomness source. More...

#include <random.h>

Collaboration diagram for FastRandomContext:
[legend]

Public Types

typedef uint64_t result_type
 

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...
 
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...
 
uint64_t operator() ()
 

Static Public Member Functions

static constexpr uint64_t min ()
 
static constexpr uint64_t max ()
 

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 45 of file random.h.

Member Typedef Documentation

Definition at line 127 of file random.h.

Constructor & Destructor Documentation

FastRandomContext::FastRandomContext ( bool  fDeterministic = false)
explicit

Definition at line 456 of file random.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

FastRandomContext::FastRandomContext ( const uint256 seed)
explicit

Initialize with explicit seed (only for testing)

Definition at line 407 of file random.cpp.

Here is the call graph for this function:

Member Function Documentation

void FastRandomContext::FillBitBuffer ( )
inlineprivate

Definition at line 67 of file random.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void FastRandomContext::FillByteBuffer ( )
inlineprivate

Definition at line 58 of file random.h.

Here is the call graph for this function:

Here is the caller graph for this function:

static constexpr uint64_t FastRandomContext::max ( )
inlinestatic

Definition at line 129 of file random.h.

static constexpr uint64_t FastRandomContext::min ( )
inlinestatic

Definition at line 128 of file random.h.

uint64_t FastRandomContext::operator() ( )
inline

Definition at line 130 of file random.h.

Here is the call graph for this function:

uint256 FastRandomContext::rand256 ( )

generate a random uint256.

Definition at line 387 of file random.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t FastRandomContext::rand32 ( )
inline

Generate a random 32-bit integer.

Definition at line 118 of file random.h.

Here is the call graph for this function:

uint64_t FastRandomContext::rand64 ( )
inline

Generate a random 64-bit integer.

Definition at line 80 of file random.h.

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t FastRandomContext::randbits ( int  bits)
inline

Generate a random (bits)-bit integer.

Definition at line 89 of file random.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool FastRandomContext::randbool ( )
inline

Generate a random boolean.

Definition at line 124 of file random.h.

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< unsigned char > FastRandomContext::randbytes ( size_t  len)

Generate random bytes.

Definition at line 398 of file random.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void FastRandomContext::RandomSeed ( )
private

Definition at line 380 of file random.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t FastRandomContext::randrange ( uint64_t  range)
inline

Generate a random integer in the range [0..range).

Definition at line 104 of file random.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

uint64_t FastRandomContext::bitbuf
private

Definition at line 53 of file random.h.

int FastRandomContext::bitbuf_size
private

Definition at line 54 of file random.h.

unsigned char FastRandomContext::bytebuf[64]
private

Definition at line 50 of file random.h.

int FastRandomContext::bytebuf_size
private

Definition at line 51 of file random.h.

bool FastRandomContext::requires_seed
private

Definition at line 47 of file random.h.

ChaCha20 FastRandomContext::rng
private

Definition at line 48 of file random.h.


The documentation for this class was generated from the following files: