File: nondet_random.html

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (131 lines) | stat: -rw-r--r-- 4,281 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<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="center" width="277" height="86">Header
<a href="../../boost/nondet_random.hpp">&lt;boost/nondet_random.hpp&gt;</a></h1>

<ul>
<li><a href="#synopsis">Synopsis</a>
<li><a href="#random_device">Class <code>random_device</code></a>
<li><a href="#performance">Performance</a>
</ul>

<h2><a name="synopsis">Header</a><code>&lt;boost/nondet_random.hpp&gt;</code>
Synopsis</h2>

<pre>
namespace boost {
  class random_device;
} // namespace boost
</pre>


<h2><a name="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>

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

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

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.


<h2><a name="performance">Performance</a></h2>

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>
<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>
Jens Maurer, 2000-06-19


</body>
</html>