mirror of
https://github.com/boostorg/random.git
synced 2026-01-19 04:22:17 +00:00
146 lines
5.2 KiB
HTML
146 lines
5.2 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
|
|
|
|
<title>Boost RNG Library - Non-Deterministic Random Number
|
|
Generators</title>
|
|
</head>
|
|
|
|
<body bgcolor="#FFFFFF" text="#000000">
|
|
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="middle"
|
|
width="277" height="86">Header <a href=
|
|
"../../boost/nondet_random.hpp"><boost/nondet_random.hpp></a></h1>
|
|
|
|
<ul>
|
|
<li><a href="#synopsis">Synopsis</a></li>
|
|
|
|
<li><a href="#random_device">Class <code>random_device</code></a></li>
|
|
|
|
<li><a href="#performance">Performance</a></li>
|
|
</ul>
|
|
|
|
<h2><a name="synopsis" id=
|
|
"synopsis">Header</a><code><boost/nondet_random.hpp></code>
|
|
Synopsis</h2>
|
|
<pre>
|
|
namespace boost {
|
|
class random_device;
|
|
} // namespace boost
|
|
</pre>
|
|
|
|
<h2><a name="random_device" id="random_device">Class
|
|
<code>random_device</code></a></h2>
|
|
|
|
<h3>Synopsis</h3>
|
|
<pre>
|
|
class random_device : noncopyable
|
|
{
|
|
public:
|
|
typedef unsigned int result_type;
|
|
static const bool has_fixed_range = true;
|
|
static const result_type min_value = /* implementation defined */;
|
|
static const result_type max_value = /* implementation defined */;
|
|
result_type min() const;
|
|
result_type max() const;
|
|
explicit random_device(const std::string& token = default_token);
|
|
~random_device();
|
|
double entropy() const;
|
|
unsigned int operator()();
|
|
};
|
|
</pre>
|
|
|
|
<h3>Description</h3>
|
|
|
|
<p>Class <code>random_device</code> models a <a href=
|
|
"random-concepts.html#nondet-rng">non-deterministic random number
|
|
generator</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 <code>random_device</code> must
|
|
not be implemented. See</p>
|
|
|
|
<blockquote>
|
|
"Randomness Recommendations for Security", D. Eastlake, S. Crocker, J.
|
|
Schiller, Network Working Group, RFC 1750, December 1994
|
|
</blockquote>for further discussions.
|
|
|
|
<p><em>Note:</em> 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.</p>
|
|
|
|
<h3>Members</h3>
|
|
<pre>
|
|
explicit random_device(const std::string& token = default_token)
|
|
</pre><strong>Effects:</strong> Constructs a <code>random_device</code>,
|
|
optionally using the given <code>token</code> as an access specification (for
|
|
example, a URL) to some implementation-defined service for monitoring a
|
|
stochastic process.
|
|
<pre>
|
|
double entropy() const
|
|
</pre><strong>Returns:</strong> An entropy estimate for the random numbers
|
|
returned by operator(), in the range <code>min()</code> to log<sub>2</sub>(
|
|
<code>max()</code>+1). A deterministic random number generator (e.g. a
|
|
pseudo-random number engine) has entropy 0.<br>
|
|
<strong>Throws:</strong> Nothing.
|
|
|
|
<h3>Implementation Note for Linux</h3>
|
|
|
|
<p>On the Linux operating system, <code>token</code> 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,
|
|
<code>std::ios_base::failure</code> is thrown. By default,
|
|
<code>random_device</code> uses the <code>/dev/urandom</code> pseudo-device
|
|
to retrieve the random numbers. Another option would be to specify the
|
|
<code>/dev/random</code> pseudo-device, which blocks on reads if the
|
|
entropy pool has no more random bits available.</p>
|
|
|
|
<h2><a name="performance" id="performance">Performance</a></h2>
|
|
|
|
<p>The test program <a href=
|
|
"nondet_random_speed.cpp">nondet_random_speed.cpp</a> measures the
|
|
execution times of the <a href=
|
|
"../../boost/nondet_random.hpp">nondet_random.hpp</a> implementation of the
|
|
above algorithms in a tight loop. The performance has been evaluated on a
|
|
Pentium Pro 200 MHz with gcc 2.95.2, Linux 2.2.13, glibc 2.1.2.</p>
|
|
|
|
<table border="1" summary="">
|
|
<tr>
|
|
<th>class</th>
|
|
|
|
<th>time per invocation [usec]</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>random_device</td>
|
|
|
|
<td>92.0</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>The measurement error is estimated at +/- 1 usec.</p>
|
|
<hr>
|
|
|
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
|
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
|
height="31" width="88"></a></p>
|
|
|
|
<p>Revised
|
|
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05
|
|
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
|
|
|
|
<p><i>Copyright © 2000-2003 <a href=
|
|
"../../people/jens_maurer.htm">Jens Maurer</a></i></p>
|
|
|
|
<p><i>Distributed under the Boost Software License, Version 1.0. (See
|
|
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
|
|
copy at <a href=
|
|
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
|
|
</body>
|
|
</html>
|