Index: boost/nondet_random.hpp
===================================================================
--- boost/nondet_random.hpp	(revision 61489)
+++ boost/nondet_random.hpp	(working copy)
@@ -23,10 +23,66 @@
 #include <boost/config.hpp>
 #include <boost/utility.hpp>            // noncopyable
 #include <boost/integer_traits.hpp>     // compile-time integral limits
+#include <boost/random/detail/auto_link.hpp>
 
 namespace boost {
 
-// use some OS service to generate non-deterministic random numbers
+/**
+ * Class \random_device models a \nondeterministic_random_number_generator.
+ * 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
+ *
+ *  @blockquote
+ *  "Randomness Recommendations for Security", D. Eastlake, S. Crocker,
+ *  J. Schiller, Network Working Group, RFC 1750, December 1994
+ *  @endblockquote
+ *
+ * for further discussions. 
+ *
+ * @xmlnote
+ * 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.
+ * @endxmlnote
+ *
+ * <b>Implementation Note for Linux</b>
+ *
+ * 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, @c std::ios_base::failure is thrown. By default,
+ * \random_device 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.
+ *
+ * <b>Inplementation Note for Windows</b>
+ *
+ * On the Windows operating system, token is interpreted as the name
+ * of a cryptographic service provider.  By default \random_device uses
+ * MS_DEF_PROV.
+ *
+ * <b>Performance</b>
+ *
+ * The test program <a href="\boost/libs/random/nondet_random_speed.cpp">
+ * nondet_random_speed.cpp</a> measures the execution times of the
+ * nondet_random.hpp 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.
+ *
+ * <table cols="2">
+ *   <tr><th>class</th><th>time per invocation [usec]</th></tr>
+ *   <tr><td> @xmlonly <classname alt="boost::random_device">random_device</classname> @endxmlonly </td><td>92.0</td></tr>
+ * </table>
+ *
+ * The measurement error is estimated at +/- 1 usec.
+ */
 class random_device : private noncopyable
 {
 public:
@@ -35,15 +91,37 @@
   BOOST_STATIC_CONSTANT(result_type, min_value = integer_traits<result_type>::const_min);
   BOOST_STATIC_CONSTANT(result_type, max_value = integer_traits<result_type>::const_max);
 
+  /**
+   * Returns: The smallest value that the \random_device can produce.
+   */
   result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return min_value; }
+  /**
+   * Returns: The largest value that the \random_device can produce.
+   */
   result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return max_value; }
-  explicit random_device(const std::string& token = default_token);
-  ~random_device();
-  double entropy() const;
-  unsigned int operator()();
+  /** 
+   * Constructs a @c 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 explicit random_device(const std::string& token = default_token);
+  BOOST_RANDOM_DECL ~random_device();
+  /**
+   * 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.
+   */
+  BOOST_RANDOM_DECL double entropy() const;
+  /**
+   * Returns: A random value in the range [min, max]
+   */
+  BOOST_RANDOM_DECL unsigned int operator()();
 
 private:
-  static const char * const default_token;
+  BOOST_RANDOM_DECL static const char * const default_token;
 
   /*
    * std:5.3.5/5 [expr.delete]: "If the object being deleted has incomplete
Index: boost/random/detail/auto_link.hpp
===================================================================
--- boost/random/detail/auto_link.hpp	(revision 0)
+++ boost/random/detail/auto_link.hpp	(revision 0)
@@ -0,0 +1,42 @@
+/* boost random auto_link.hpp header file
+ *
+ * Copyright Steven Watanabe 2010
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * $Id$
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_AUTO_LINK_HPP
+#define BOOST_RANDOM_DETAIL_AUTO_LINK_HPP
+
+#include <boost/config.hpp>
+
+#ifdef BOOST_HAS_DECLSPEC
+    #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_RANDOM_DYN_LINK)
+        #if defined(BOOST_RANDOM_SOURCE)
+            #define BOOST_RANDOM_DECL __declspec(dllexport)
+        #else
+            #define BOOST_RANDOM_DECL __declspec(dllimport)
+        #endif
+    #endif
+#endif
+
+#ifndef BOOST_RANDOM_DECL
+    #define BOOST_RANDOM_DECL
+#endif
+
+#if !defined(BOOST_RANDOM_NO_LIB) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_RANDOM_SOURCE)
+
+#define BOOST_LIB_NAME boost_random
+
+#if defined(BOOST_RANDOM_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
+    #define BOOST_DYN_LINK
+#endif
+
+#include <boost/config/auto_link.hpp>
+
+#endif
+
+#endif

Property changes on: boost\random\detail\auto_link.hpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Index: libs/random/src/random_device.cpp
===================================================================
--- libs/random/src/random_device.cpp	(revision 0)
+++ libs/random/src/random_device.cpp	(revision 0)
@@ -0,0 +1,202 @@
+/* boost random_device.cpp implementation
+ *
+ * Copyright Jens Maurer 2000
+ * Copyright Steven Watanabe 2010
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * $Id$
+ *
+ */
+
+#define BOOST_RANDOM_SOURCE
+
+#include <boost/nondet_random.hpp>
+#include <string>
+#include <cassert>
+
+
+#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
+//  A definition is required even for integral static constants
+const bool boost::random_device::has_fixed_range;
+const boost::random_device::result_type boost::random_device::min_value;
+const boost::random_device::result_type boost::random_device::max_value;
+#endif
+
+
+#if defined(BOOST_WINDOWS)
+
+#include <windows.h>
+#include <wincrypt.h>
+#include <stdexcept>  // std::invalid_argument
+
+// mingw's wincrypt.h appears to be out of date
+WINADVAPI
+BOOL
+WINAPI
+CryptEnumProvidersA(
+    DWORD dwIndex,
+    DWORD *pdwReserved,
+    DWORD dwFlags,
+    DWORD *pdwProvType,
+    LPSTR szProvName,
+    DWORD *pcbProvName
+    );
+
+#pragma comment(lib, "Advapi32.lib")
+
+BOOST_RANDOM_DECL const char * const boost::random_device::default_token = MS_DEF_PROV_A;
+
+class boost::random_device::impl
+{
+public:
+  impl(const std::string & token) : provider(token) {
+    char buffer[80];
+    DWORD type;
+    DWORD len;
+
+    // Find the type of the provider
+    for(DWORD i = 0; ; ++i) {
+      len = sizeof(buffer);
+      if(!CryptEnumProvidersA(i, NULL, 0, &type, buffer, &len)) {
+        error("Could not find provider name");
+      }
+      if(buffer == provider) {
+        break;
+      }
+    }
+
+    if(!CryptAcquireContextA(&hProv, NULL, provider.c_str(), type,
+        CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
+      error("Could not acquire CSP context");
+    }
+  }
+
+  ~impl() {
+    if(!CryptReleaseContext(hProv, 0)) error("Could not release CSP context");
+  }
+
+  unsigned int next() {
+    unsigned int result;
+
+    if(!CryptGenRandom(hProv, sizeof(result),
+        static_cast<BYTE*>(static_cast<void*>(&result)))) {
+      error("error while reading");
+    }
+
+    return result;
+  }
+
+private:
+  void error(const std::string & msg) {
+    char buf[80];
+    DWORD num = FormatMessageA(
+      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+      NULL,
+      GetLastError(),
+      0,
+      buf,
+      sizeof(buf),
+      NULL);
+
+    throw std::invalid_argument("boost::random_device: " + msg + 
+                                " Cryptopraphic Service Provider " + provider + 
+                                ": " + std::string(&buf[0], &buf[0] + num));
+  }
+  const std::string provider;
+  HCRYPTPROV hProv;
+};
+
+#else
+
+// the default is the unlimited capacity device, using some secure hash
+// try "/dev/random" for blocking when the entropy pool has drained
+const char * const boost::random_device::default_token = "/dev/urandom";
+
+/*
+ * This uses the POSIX interface for unbuffered reading.
+ * Using buffered std::istream would consume entropy which may
+ * not actually be used.  Entropy is a precious good we avoid
+ * wasting.
+ */
+
+#if defined(__GNUC__) && defined(_CXXRT_STD_NAME)
+// I have severe difficulty to get the POSIX includes to work with
+// -fhonor-std and Dietmar Kühl's standard C++ library.  Hack around that
+// problem for now.
+extern "C" {
+static const int O_RDONLY = 0;
+extern int open(const char *__file, int __oflag, ...);
+extern int read(int __fd, __ptr_t __buf, size_t __nbytes);
+extern int close(int __fd);
+}
+#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>    // open
+#include <unistd.h>   // read, close
+#endif
+
+#include <errno.h>    // errno
+#include <string.h>   // strerror
+#include <stdexcept>  // std::invalid_argument
+
+
+class boost::random_device::impl
+{
+public:
+  impl(const std::string & token) : path(token) {
+    fd = open(token.c_str(), O_RDONLY);
+    if(fd < 0)
+      error("cannot open");
+  }
+
+  ~impl() { if(close(fd) < 0) error("could not close"); }
+
+  unsigned int next() {
+    unsigned int result;
+    long sz = read(fd, reinterpret_cast<char *>(&result), sizeof(result));
+    if(sz == -1)
+      error("error while reading");
+    else if(sz != sizeof(result)) {
+      errno = 0;
+      error("EOF while reading");
+    }
+    return result;
+  }
+
+private:
+  void error(const std::string & msg) {
+    throw std::invalid_argument("boost::random_device: " + msg + 
+                                " random-number pseudo-device " + path + 
+                                ": " + strerror(errno));
+  }
+  const std::string path;
+  int fd;
+};
+
+#endif // BOOST_WINDOWS
+
+BOOST_RANDOM_DECL boost::random_device::random_device(const std::string& token)
+  : pimpl(new impl(token))
+{
+  assert((std::numeric_limits<result_type>::max)() == max_value);
+}
+
+BOOST_RANDOM_DECL boost::random_device::~random_device()
+{
+  // the complete class impl is now visible, so we're safe
+  // (see comment in random.hpp)
+  delete pimpl;
+}
+
+BOOST_RANDOM_DECL double boost::random_device::entropy() const
+{
+  return 10;
+}
+
+BOOST_RANDOM_DECL unsigned int boost::random_device::operator()()
+{
+  return pimpl->next();
+}

Property changes on: libs\random\src\random_device.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Index: libs/random/build/Jamfile.v2
===================================================================
--- libs/random/build/Jamfile.v2	(revision 0)
+++ libs/random/build/Jamfile.v2	(revision 0)
@@ -0,0 +1,18 @@
+# Jamfile.v2
+#
+# Copyright (c) 2010
+# Steven Watanabe
+#
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+project /boost/random
+  : source-location ../src
+  : requirements <link>shared:<define>BOOST_RANDOM_DYN_LINK
+  : usage-requirements <link>shared:<define>BOOST_RANDOM_DYN_LINK
+;
+
+lib boost_random : [ glob *.cpp ] ;
+
+boost-install boost_random ;

Property changes on: libs\random\build\Jamfile.v2
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

