Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.


/* boost nondet_random.hpp header file
 * Copyright Jens Maurer 2000
 * Permission to use, copy, modify, sell, and distribute this software
 * is hereby granted without fee provided that the above copyright notice
 * appears in all copies and that both that copyright notice and this
 * permission notice appear in supporting documentation,
 * Jens Maurer makes no representations about the suitability of this
 * software for any purpose. It is provided "as is" without express or
 * implied warranty.
 * $Id: nondet_random.hpp,v 1.7 2002/12/27 16:51:52 beman_dawes Exp $
 * Revision history
 *  2000-02-18  Portability fixes (thanks to Beman Dawes)

//  See for documentation.


#include <string>                       // std::abs
#include <algorithm>                    // std::min
#include <cmath>
#include <boost/config.hpp>
#include <boost/utility.hpp>            // noncopyable
#include <boost/integer_traits.hpp>     // compile-time integral limits

namespace boost {

// use some OS service to generate non-deterministic random numbers
class random_device : private noncopyable
  typedef unsigned int result_type;
  BOOST_STATIC_CONSTANT(bool, has_fixed_range = true);
  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);

  result_type min() const { return min_value; }
  result_type max() const { return max_value; }
  explicit random_device(const std::string& token = default_token);
  double entropy() const;
  unsigned int operator()();

  static const char * const default_token;

   * std:5.3.5/5 [expr.delete]: "If the object being deleted has incomplete
   * class type at the point of deletion and the complete class has a
   * non-trivial destructor [...], the behavior is undefined".
   * This disallows the use of scoped_ptr<> with pimpl-like classes
   * having a non-trivial destructor.
  class impl;
  impl * pimpl;

// TODO: put Schneier's Yarrow-160 algorithm here.

} // namespace boost