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:

Public Types

typedef uint64_t result_type

Public Member Functions

 FastRandomContext (bool fDeterministic=false) noexcept
 FastRandomContext (const uint256 &seed) noexcept
 Initialize with explicit seed (only for testing) More...
 FastRandomContext (const FastRandomContext &)=delete
 FastRandomContext (FastRandomContext &&)=delete
FastRandomContextoperator= (const FastRandomContext &)=delete
FastRandomContextoperator= (FastRandomContext &&from) noexcept
 Move a FastRandomContext. More...
uint64_t rand64 () noexcept
 Generate a random 64-bit integer. More...
uint64_t randbits (int bits) noexcept
 Generate a random (bits)-bit integer. More...
uint64_t randrange (uint64_t range) noexcept
 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 () noexcept
 Generate a random 32-bit integer. More...
uint256 rand256 () noexcept
 generate a random uint256. More...
bool randbool () noexcept
 Generate a random boolean. More...
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.

Definition at line 95 of file random.h.

Member Typedef Documentation

◆ result_type

Definition at line 185 of file random.h.

Constructor & Destructor Documentation

◆ FastRandomContext() [1/4]

FastRandomContext::FastRandomContext ( bool  fDeterministic = false)

Definition at line 613 of file random.cpp.

Here is the call graph for this function:

◆ FastRandomContext() [2/4]

FastRandomContext::FastRandomContext ( const uint256 seed)

Initialize with explicit seed (only for testing)

Definition at line 562 of file random.cpp.

◆ FastRandomContext() [3/4]

FastRandomContext::FastRandomContext ( const FastRandomContext )

◆ FastRandomContext() [4/4]

FastRandomContext::FastRandomContext ( FastRandomContext &&  )

Member Function Documentation

◆ FillBitBuffer()

void FastRandomContext::FillBitBuffer ( )

Definition at line 117 of file random.h.

◆ FillByteBuffer()

void FastRandomContext::FillByteBuffer ( )

Definition at line 108 of file random.h.

Here is the call graph for this function:

◆ max()

static constexpr uint64_t FastRandomContext::max ( )

Definition at line 187 of file random.h.

◆ min()

static constexpr uint64_t FastRandomContext::min ( )

Definition at line 186 of file random.h.

◆ operator()()

uint64_t FastRandomContext::operator() ( )

Definition at line 188 of file random.h.

◆ operator=() [1/2]

FastRandomContext& FastRandomContext::operator= ( const FastRandomContext )

◆ operator=() [2/2]

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

Move a FastRandomContext.

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

Definition at line 622 of file random.cpp.

◆ rand256()

uint256 FastRandomContext::rand256 ( )

generate a random uint256.

Definition at line 541 of file random.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rand32()

uint32_t FastRandomContext::rand32 ( )

Generate a random 32-bit integer.

Definition at line 176 of file random.h.

◆ rand64()

uint64_t FastRandomContext::rand64 ( )

Generate a random 64-bit integer.

Definition at line 138 of file random.h.

◆ randbits()

uint64_t FastRandomContext::randbits ( int  bits)

Generate a random (bits)-bit integer.

Definition at line 147 of file random.h.

◆ randbool()

bool FastRandomContext::randbool ( )

Generate a random boolean.

Definition at line 182 of file random.h.

◆ randbytes()

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

Generate random bytes.

Definition at line 552 of file random.cpp.

◆ RandomSeed()

void FastRandomContext::RandomSeed ( )

Definition at line 534 of file random.cpp.

Here is the call graph for this function:

◆ randrange()

uint64_t FastRandomContext::randrange ( uint64_t  range)

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

Definition at line 162 of file random.h.

Here is the caller graph for this function:

Member Data Documentation

◆ bitbuf

uint64_t FastRandomContext::bitbuf

Definition at line 103 of file random.h.

◆ bitbuf_size

int FastRandomContext::bitbuf_size

Definition at line 104 of file random.h.

◆ bytebuf

unsigned char FastRandomContext::bytebuf[64]

Definition at line 100 of file random.h.

◆ bytebuf_size

int FastRandomContext::bytebuf_size

Definition at line 101 of file random.h.

◆ requires_seed

bool FastRandomContext::requires_seed

Definition at line 97 of file random.h.

◆ rng

ChaCha20 FastRandomContext::rng

Definition at line 98 of file random.h.

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