Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::random::random_device Class Reference

Class models a . More...

#include <random_device.hpp>

Inheritance diagram for boost::random::random_device:
Collaboration diagram for boost::random::random_device:

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...
 

Detailed Description

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.

Platformtime per invocation [microseconds]
Windows 2.9
Linux 1.7

The measurement error is estimated at +/- 1 usec.

Member Typedef Documentation

Constructor & Destructor Documentation

BOOST_RANDOM_DECL boost::random::random_device::random_device ( )

Constructs a random_device, optionally using the default device.

BOOST_RANDOM_DECL boost::random::random_device::random_device ( const std::string &  token)
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 ( )

Member Function Documentation

static result_type min boost::random::random_device::BOOST_PREVENT_MACRO_SUBSTITUTION ( )
inlinestatic

Returns the smallest value that the can produce.

static result_type max boost::random::random_device::BOOST_PREVENT_MACRO_SUBSTITUTION ( )
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

Returns: An entropy estimate for the random numbers returned by operator(), in the range min() to log2( max()+1).

A deterministic random number generator (e.g. a pseudo-random number engine) has entropy 0.

Throws: Nothing.

template<class Iter >
void boost::random::random_device::generate ( Iter  begin,
Iter  end 
)
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].


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