ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
ucommon::Random Class Reference

Cryptographically relevant random numbers. More...

#include <secure.h>

Static Public Member Functions

static bool seed (const uint8_t *buffer, size_t size)
 Push entropic seed. More...
 
static void seed (void)
 Re-seed pseudo-random generation and entropy pools. More...
 
static size_t key (uint8_t *memory, size_t size)
 Get high-entropy random data. More...
 
static size_t fill (uint8_t *memory, size_t size)
 Fill memory with pseudo-random values. More...
 
static int get (void)
 Get a pseudo-random integer, range 0 - 32767. More...
 
static int get (int min, int max)
 Get a pseudo-random integer in a preset range. More...
 
static double real (void)
 Get a pseudo-random floating point value. More...
 
static double real (double min, double max)
 Get a pseudo-random floating point value in a preset range. More...
 
static bool status (void)
 Determine if we have sufficient entropy to return random values. More...
 
static void uuid (char *string)
 Create 36 character random uuid string. More...
 
static secure::string uuid (void)
 
template<class T >
static T value (void)
 
template<class T >
static T value (T max)
 
template<class T >
static T value (T min, T max)
 

Private Member Functions

 __DELETE_DEFAULTS (Random)
 

Detailed Description

Cryptographically relevant random numbers.

This is used both to gather entropy pools and pseudo-random values.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 765 of file secure.h.

Member Function Documentation

◆ __DELETE_DEFAULTS()

ucommon::Random::__DELETE_DEFAULTS ( Random  )
private

◆ fill()

size_t ucommon::Random::fill ( uint8_t *  memory,
size_t  size 
)
static

Fill memory with pseudo-random values.

This is used as the basis for all get and real operations and does not depend on seed entropy.

Parameters
memorybuffer to fill.
sizeof buffer to fill.
Returns
number of bytes set.

Definition at line 40 of file random.cpp.

Referenced by scrub(), ucommon::secure::uuid(), and zerofill().

◆ get() [1/2]

int ucommon::Random::get ( int  min,
int  max 
)
static

Get a pseudo-random integer in a preset range.

Parameters
minvalue of random integer.
maxvalue of random integer.
Returns
random value from min to max.

Definition at line 658 of file common.cpp.

References ucommon::max(), and ucommon::min().

Here is the call graph for this function:

◆ get() [2/2]

int ucommon::Random::get ( void  )
static

Get a pseudo-random integer, range 0 - 32767.

Returns
random integer.

Definition at line 650 of file common.cpp.

◆ key()

size_t ucommon::Random::key ( uint8_t *  memory,
size_t  size 
)
static

Get high-entropy random data.

This is often used to initialize keys. This operation may block if there is insufficient entropy immediately available.

Parameters
memorybuffer to fill.
sizeof buffer.
Returns
number of bytes filled.

Definition at line 34 of file random.cpp.

◆ real() [1/2]

double ucommon::Random::real ( double  min,
double  max 
)
static

Get a pseudo-random floating point value in a preset range.

Parameters
minvalue of random floating point number.
maxvalue of random floating point number.
Returns
random value from min to max.

Definition at line 687 of file common.cpp.

References ucommon::max(), and ucommon::min().

Here is the call graph for this function:

◆ real() [2/2]

double ucommon::Random::real ( void  )
static

Get a pseudo-random floating point value.

Returns
psudo-random value 0 to 1.

Definition at line 676 of file common.cpp.

◆ seed() [1/2]

bool ucommon::Random::seed ( const uint8_t *  buffer,
size_t  size 
)
static

Push entropic seed.

Parameters
bufferof random data to push.
sizeof buffer.
Returns
true if successful.

Definition at line 28 of file random.cpp.

References ucommon::secure::init().

Here is the call graph for this function:

◆ seed() [2/2]

void ucommon::Random::seed ( void  )
static

Re-seed pseudo-random generation and entropy pools.

Definition at line 23 of file random.cpp.

References ucommon::secure::init().

Here is the call graph for this function:

◆ status()

bool ucommon::Random::status ( void  )
static

Determine if we have sufficient entropy to return random values.

Returns
true if sufficient entropy.

Definition at line 46 of file random.cpp.

◆ uuid() [1/2]

void ucommon::Random::uuid ( char *  string)
static

Create 36 character random uuid string.

Parameters
stringto write uuid into, must be 37 bytes or more.

Definition at line 692 of file common.cpp.

References ucommon::String::hexdump(), and ucommon::str().

Here is the call graph for this function:

◆ uuid() [2/2]

secure::string ucommon::Random::uuid ( void  )
static

Definition at line 704 of file common.cpp.

◆ value() [1/3]

template<class T >
static T ucommon::Random::value ( max)
inlinestatic

Definition at line 855 of file secure.h.

References ucommon::max().

Here is the call graph for this function:

◆ value() [2/3]

template<class T >
static T ucommon::Random::value ( min,
max 
)
inlinestatic

Definition at line 868 of file secure.h.

References ucommon::max(), and ucommon::min().

Here is the call graph for this function:

◆ value() [3/3]

template<class T >
static T ucommon::Random::value ( void  )
inlinestatic

Definition at line 848 of file secure.h.


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