Bitcoin
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FastRandomContext Class Reference

#include <random.h>

Public Types

typedef uint64_t result_type
 

Public Member Functions

 FastRandomContext (bool fDeterministic=false) noexcept
 
 FastRandomContext (const uint256 &seed) noexcept
 
 FastRandomContext (const FastRandomContext &)=delete
 
 FastRandomContext (FastRandomContext &&)=delete
 
FastRandomContextoperator= (const FastRandomContext &)=delete
 
FastRandomContextoperator= (FastRandomContext &&from) noexcept
 
uint64_t rand64 () noexcept
 
uint64_t randbits (int bits) noexcept
 
uint64_t randrange (uint64_t range) noexcept
 
std::vector< unsigned char > randbytes (size_t len)
 
uint32_t rand32 () noexcept
 
uint256 rand256 () noexcept
 
bool randbool () noexcept
 
uint64_t operator() () noexcept
 

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 does not gather more entropy after that.

This class is not thread-safe.

Member Typedef Documentation

◆ result_type

Constructor & Destructor Documentation

◆ FastRandomContext() [1/4]

FastRandomContext::FastRandomContext ( bool  fDeterministic = false)
explicitnoexcept

◆ FastRandomContext() [2/4]

FastRandomContext::FastRandomContext ( const uint256 seed)
explicitnoexcept

Initialize with explicit seed (only for testing)

◆ FastRandomContext() [3/4]

FastRandomContext::FastRandomContext ( const FastRandomContext )
delete

◆ FastRandomContext() [4/4]

FastRandomContext::FastRandomContext ( FastRandomContext &&  )
delete

Member Function Documentation

◆ FillBitBuffer()

void FastRandomContext::FillBitBuffer ( )
inlineprivate

◆ FillByteBuffer()

void FastRandomContext::FillByteBuffer ( )
inlineprivate

◆ max()

static constexpr uint64_t FastRandomContext::max ( )
inlinestatic

◆ min()

static constexpr uint64_t FastRandomContext::min ( )
inlinestatic

◆ operator()()

uint64_t FastRandomContext::operator() ( )
inlinenoexcept

◆ operator=() [1/2]

FastRandomContext& FastRandomContext::operator= ( const FastRandomContext )
delete

◆ operator=() [2/2]

FastRandomContext & FastRandomContext::operator= ( FastRandomContext &&  from)
noexcept

Move a FastRandomContext. If the original one is used again, it will be reseeded.

◆ rand256()

uint256 FastRandomContext::rand256 ( )
noexcept

generate a random uint256.

◆ rand32()

uint32_t FastRandomContext::rand32 ( )
inlinenoexcept

Generate a random 32-bit integer.

◆ rand64()

uint64_t FastRandomContext::rand64 ( )
inlinenoexcept

Generate a random 64-bit integer.

◆ randbits()

uint64_t FastRandomContext::randbits ( int  bits)
inlinenoexcept

Generate a random (bits)-bit integer.

◆ randbool()

bool FastRandomContext::randbool ( )
inlinenoexcept

Generate a random boolean.

◆ randbytes()

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

Generate random bytes.

◆ RandomSeed()

void FastRandomContext::RandomSeed ( )
private

◆ randrange()

uint64_t FastRandomContext::randrange ( uint64_t  range)
inlinenoexcept

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

Member Data Documentation

◆ bitbuf

uint64_t FastRandomContext::bitbuf
private

◆ bitbuf_size

int FastRandomContext::bitbuf_size
private

◆ bytebuf

unsigned char FastRandomContext::bytebuf[64]
private

◆ bytebuf_size

int FastRandomContext::bytebuf_size
private

◆ requires_seed

bool FastRandomContext::requires_seed
private

◆ rng

ChaCha20 FastRandomContext::rng
private

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