OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::random_source Class Reference

Generates pseudo-random numbers from a given entropy source. More...

#include <random_source.hpp>

Public Types

using result_type = unsigned int
 

Public Member Functions

 random_source (const std::string &source_file)
 Constructor.
 
 ~random_source ()=default
 
 random_source (const random_source &other)=delete
 
auto operator= (const random_source &other)=delete
 
 random_source (random_source &&other)=delete
 
auto operator= (random_source &&other)=delete
 
auto operator() () -> result_type
 Returns a new random integer.
 
auto random_hash () -> hash_t
 Returns a random 32-byte hash value.
 

Static Public Member Functions

static constexpr auto min () -> result_type
 Returns the minimum random value this source can produce.
 
static constexpr auto max () -> result_type
 Returns the maximum random value this source can produce.
 

Detailed Description

Generates pseudo-random numbers from a given entropy source.

Construct with the path to an entropy source (usually /dev/urandom) to seed the pseudo-random number generator. After initial setup, random_source uses SHA256 to generate further random numbers using a counter. Compatible with std::uniform_int_distribution.

Definition at line 27 of file random_source.hpp.

Member Typedef Documentation

◆ result_type

using cbdc::random_source::result_type = unsigned int

Definition at line 29 of file random_source.hpp.

Constructor & Destructor Documentation

◆ random_source() [1/3]

cbdc::random_source::random_source ( const std::string & source_file)
explicit

Constructor.

Seeds the SHA256 engine with the entropy source.

Parameters
source_filepath to a file to use as a seed.

Definition at line 14 of file random_source.cpp.

◆ ~random_source()

cbdc::random_source::~random_source ( )
default

◆ random_source() [2/3]

cbdc::random_source::random_source ( const random_source & other)
delete

◆ random_source() [3/3]

cbdc::random_source::random_source ( random_source && other)
delete

Member Function Documentation

◆ max()

static constexpr auto cbdc::random_source::max ( ) -> result_type
inlinestaticconstexpr

Returns the maximum random value this source can produce.

Returns
the maximum random value.

Definition at line 54 of file random_source.hpp.

◆ min()

static constexpr auto cbdc::random_source::min ( ) -> result_type
inlinestaticconstexpr

Returns the minimum random value this source can produce.

Returns
the minimum random value.

Definition at line 48 of file random_source.hpp.

◆ operator()()

auto cbdc::random_source::operator() ( ) -> result_type

Returns a new random integer.

Returns
random integer.

Definition at line 26 of file random_source.cpp.

◆ operator=() [1/2]

auto cbdc::random_source::operator= ( const random_source & other)
delete

◆ operator=() [2/2]

auto cbdc::random_source::operator= ( random_source && other)
delete

◆ random_hash()

auto cbdc::random_source::random_hash ( ) -> hash_t

Returns a random 32-byte hash value.

Can generate secure-random unique identifiers (UIDs) or private keys.

Returns
a random 32-byte value.

Definition at line 44 of file random_source.cpp.


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