Class models a . More...
#include <random_device.hpp>
Public Types | |
typedef unsigned int | result_type |
Public Member Functions | |
BOOST_STATIC_CONSTANT (bool, has_fixed_range=false) | |
BOOST_RANDOM_DECL | random_device () |
Constructs a random_device , optionally using the default device. More... | |
BOOST_RANDOM_DECL | random_device (const std::string &token) |
Constructs a random_device , optionally using the given token as an access specification (for example, a URL) to some implementation-defined service for monitoring a stochastic process. More... | |
BOOST_RANDOM_DECL | ~random_device () |
BOOST_RANDOM_DECL double | entropy () const |
Returns: An entropy estimate for the random numbers returned by operator(), in the range min() to log2( max()+1). More... | |
BOOST_RANDOM_DECL unsigned int | operator() () |
Returns a random value in the range [min, max]. More... | |
template<class Iter > | |
void | generate (Iter begin, Iter end) |
Fills a range with random 32-bit values. More... | |
Static Public Member Functions | |
static result_type min | BOOST_PREVENT_MACRO_SUBSTITUTION () |
Returns the smallest value that the can produce. More... | |
static result_type max | BOOST_PREVENT_MACRO_SUBSTITUTION () |
Returns the largest value that the can produce. More... | |
Class models a .
It uses one or more implementation-defined stochastic processes to generate a sequence of uniformly distributed non-deterministic random numbers. For those environments where a non-deterministic random number generator is not available, class random_device must not be implemented. See
"Randomness Recommendations for Security", D. Eastlake, S. Crocker, J. Schiller, Network Working Group, RFC 1750, December 1994
for further discussions.
Some operating systems abstract the computer hardware enough to make it difficult to non-intrusively monitor stochastic processes. However, several do provide a special device for exactly this purpose. It seems to be impossible to emulate the functionality using Standard C++ only, so users should be aware that this class may not be available on all platforms.
Implementation Note for Linux
On the Linux operating system, token is interpreted as a filesystem path. It is assumed that this path denotes an operating system pseudo-device which generates a stream of non-deterministic random numbers. The pseudo-device should never signal an error or end-of-file. Otherwise, std::ios_base::failure
is thrown. By default, uses the /dev/urandom pseudo-device to retrieve the random numbers. Another option would be to specify the /dev/random pseudo-device, which blocks on reads if the entropy pool has no more random bits available.
Implementation Note for Windows
On the Windows operating system, token is interpreted as the name of a cryptographic service provider. By default uses MS_DEF_PROV.
Performance
The test program nondet_random_speed.cpp measures the execution times of the random_device.hpp implementation of the above algorithms in a tight loop. The performance has been evaluated on an Intel(R) Core(TM) i7 CPU Q 840 @ 1.87GHz, 1867 Mhz with Visual C++ 2010, Microsoft Windows 7 Professional and with gcc 4.4.5, Ubuntu Linux 2.6.35-25-generic.
Platform | time per invocation [microseconds] |
---|---|
Windows | 2.9 |
Linux | 1.7 |
The measurement error is estimated at +/- 1 usec.
typedef unsigned int boost::random::random_device::result_type |
BOOST_RANDOM_DECL boost::random::random_device::random_device | ( | ) |
Constructs a random_device
, optionally using the default device.
|
explicit |
Constructs a random_device
, optionally using the given token as an access specification (for example, a URL) to some implementation-defined service for monitoring a stochastic process.
BOOST_RANDOM_DECL boost::random::random_device::~random_device | ( | ) |
|
inlinestatic |
Returns the smallest value that the can produce.
|
inlinestatic |
Returns the largest value that the can produce.
boost::random::random_device::BOOST_STATIC_CONSTANT | ( | bool | , |
has_fixed_range | = false |
||
) |
BOOST_RANDOM_DECL double boost::random::random_device::entropy | ( | ) | const |
|
inline |
Fills a range with random 32-bit values.
References boost::asio::begin, and boost::end.
BOOST_RANDOM_DECL unsigned int boost::random::random_device::operator() | ( | ) |
Returns a random value in the range [min, max].