[29] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
| 2 | |
---|
| 3 | <html> |
---|
| 4 | <head> |
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
---|
| 6 | |
---|
| 7 | <title>Boost RNG Library - Non-Deterministic Random Number |
---|
| 8 | Generators</title> |
---|
| 9 | </head> |
---|
| 10 | |
---|
| 11 | <body bgcolor="#FFFFFF" text="#000000"> |
---|
| 12 | <h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="middle" |
---|
| 13 | width="277" height="86">Header <a href= |
---|
| 14 | "../../boost/nondet_random.hpp"><boost/nondet_random.hpp></a></h1> |
---|
| 15 | |
---|
| 16 | <ul> |
---|
| 17 | <li><a href="#synopsis">Synopsis</a></li> |
---|
| 18 | |
---|
| 19 | <li><a href="#random_device">Class <code>random_device</code></a></li> |
---|
| 20 | |
---|
| 21 | <li><a href="#performance">Performance</a></li> |
---|
| 22 | </ul> |
---|
| 23 | |
---|
| 24 | <h2><a name="synopsis" id= |
---|
| 25 | "synopsis">Header</a><code><boost/nondet_random.hpp></code> |
---|
| 26 | Synopsis</h2> |
---|
| 27 | <pre> |
---|
| 28 | namespace boost { |
---|
| 29 | class random_device; |
---|
| 30 | } // namespace boost |
---|
| 31 | </pre> |
---|
| 32 | |
---|
| 33 | <h2><a name="random_device" id="random_device">Class |
---|
| 34 | <code>random_device</code></a></h2> |
---|
| 35 | |
---|
| 36 | <h3>Synopsis</h3> |
---|
| 37 | <pre> |
---|
| 38 | class random_device : noncopyable |
---|
| 39 | { |
---|
| 40 | public: |
---|
| 41 | typedef unsigned int result_type; |
---|
| 42 | static const bool has_fixed_range = true; |
---|
| 43 | static const result_type min_value = /* implementation defined */; |
---|
| 44 | static const result_type max_value = /* implementation defined */; |
---|
| 45 | result_type min() const; |
---|
| 46 | result_type max() const; |
---|
| 47 | explicit random_device(const std::string& token = default_token); |
---|
| 48 | ~random_device(); |
---|
| 49 | double entropy() const; |
---|
| 50 | unsigned int operator()(); |
---|
| 51 | }; |
---|
| 52 | </pre> |
---|
| 53 | |
---|
| 54 | <h3>Description</h3> |
---|
| 55 | |
---|
| 56 | <p>Class <code>random_device</code> models a <a href= |
---|
| 57 | "random-concepts.html#nondet-rng">non-deterministic random number |
---|
| 58 | generator</a>. It uses one or more implementation-defined stochastic |
---|
| 59 | processes to generate a sequence of uniformly distributed non-deterministic |
---|
| 60 | random numbers. For those environments where a non-deterministic random |
---|
| 61 | number generator is not available, class <code>random_device</code> must |
---|
| 62 | not be implemented. See</p> |
---|
| 63 | |
---|
| 64 | <blockquote> |
---|
| 65 | "Randomness Recommendations for Security", D. Eastlake, S. Crocker, J. |
---|
| 66 | Schiller, Network Working Group, RFC 1750, December 1994 |
---|
| 67 | </blockquote>for further discussions. |
---|
| 68 | |
---|
| 69 | <p><em>Note:</em> Some operating systems abstract the computer hardware |
---|
| 70 | enough to make it difficult to non-intrusively monitor stochastic |
---|
| 71 | processes. However, several do provide a special device for exactly this |
---|
| 72 | purpose. It seems to be impossible to emulate the functionality using |
---|
| 73 | Standard C++ only, so users should be aware that this class may not be |
---|
| 74 | available on all platforms.</p> |
---|
| 75 | |
---|
| 76 | <h3>Members</h3> |
---|
| 77 | <pre> |
---|
| 78 | explicit random_device(const std::string& token = default_token) |
---|
| 79 | </pre><strong>Effects:</strong> Constructs a <code>random_device</code>, |
---|
| 80 | optionally using the given <code>token</code> as an access specification (for |
---|
| 81 | example, a URL) to some implementation-defined service for monitoring a |
---|
| 82 | stochastic process. |
---|
| 83 | <pre> |
---|
| 84 | double entropy() const |
---|
| 85 | </pre><strong>Returns:</strong> An entropy estimate for the random numbers |
---|
| 86 | returned by operator(), in the range <code>min()</code> to log<sub>2</sub>( |
---|
| 87 | <code>max()</code>+1). A deterministic random number generator (e.g. a |
---|
| 88 | pseudo-random number engine) has entropy 0.<br> |
---|
| 89 | <strong>Throws:</strong> Nothing. |
---|
| 90 | |
---|
| 91 | <h3>Implementation Note for Linux</h3> |
---|
| 92 | |
---|
| 93 | <p>On the Linux operating system, <code>token</code> is interpreted as a |
---|
| 94 | filesystem path. It is assumed that this path denotes an operating system |
---|
| 95 | pseudo-device which generates a stream of non-deterministic random numbers. |
---|
| 96 | The pseudo-device should never signal an error or end-of-file. Otherwise, |
---|
| 97 | <code>std::ios_base::failure</code> is thrown. By default, |
---|
| 98 | <code>random_device</code> uses the <code>/dev/urandom</code> pseudo-device |
---|
| 99 | to retrieve the random numbers. Another option would be to specify the |
---|
| 100 | <code>/dev/random</code> pseudo-device, which blocks on reads if the |
---|
| 101 | entropy pool has no more random bits available.</p> |
---|
| 102 | |
---|
| 103 | <h2><a name="performance" id="performance">Performance</a></h2> |
---|
| 104 | |
---|
| 105 | <p>The test program <a href= |
---|
| 106 | "nondet_random_speed.cpp">nondet_random_speed.cpp</a> measures the |
---|
| 107 | execution times of the <a href= |
---|
| 108 | "../../boost/nondet_random.hpp">nondet_random.hpp</a> implementation of the |
---|
| 109 | above algorithms in a tight loop. The performance has been evaluated on a |
---|
| 110 | Pentium Pro 200 MHz with gcc 2.95.2, Linux 2.2.13, glibc 2.1.2.</p> |
---|
| 111 | |
---|
| 112 | <table border="1" summary=""> |
---|
| 113 | <tr> |
---|
| 114 | <th>class</th> |
---|
| 115 | |
---|
| 116 | <th>time per invocation [usec]</th> |
---|
| 117 | </tr> |
---|
| 118 | |
---|
| 119 | <tr> |
---|
| 120 | <td>random_device</td> |
---|
| 121 | |
---|
| 122 | <td>92.0</td> |
---|
| 123 | </tr> |
---|
| 124 | </table> |
---|
| 125 | |
---|
| 126 | <p>The measurement error is estimated at +/- 1 usec.</p> |
---|
| 127 | <hr> |
---|
| 128 | |
---|
| 129 | <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= |
---|
| 130 | "http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" |
---|
| 131 | height="31" width="88"></a></p> |
---|
| 132 | |
---|
| 133 | <p>Revised |
---|
| 134 | <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 |
---|
| 135 | December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p> |
---|
| 136 | |
---|
| 137 | <p><i>Copyright © 2000-2003 <a href= |
---|
| 138 | "../../people/jens_maurer.htm">Jens Maurer</a></i></p> |
---|
| 139 | |
---|
| 140 | <p><i>Distributed under the Boost Software License, Version 1.0. (See |
---|
| 141 | accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or |
---|
| 142 | copy at <a href= |
---|
| 143 | "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> |
---|
| 144 | </body> |
---|
| 145 | </html> |
---|