nondet_random.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* boost nondet_random.hpp header file
  2. *
  3. * Copyright Jens Maurer 2000
  4. * Distributed under the Boost Software License, Version 1.0. (See
  5. * accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * $Id: nondet_random.hpp 49314 2008-10-13 09:00:03Z johnmaddock $
  9. *
  10. * Revision history
  11. * 2000-02-18 Portability fixes (thanks to Beman Dawes)
  12. */
  13. // See http://www.boost.org/libs/random for documentation.
  14. #ifndef BOOST_NONDET_RANDOM_HPP
  15. #define BOOST_NONDET_RANDOM_HPP
  16. #include <string> // std::abs
  17. #include <algorithm> // std::min
  18. #include <boost/config/no_tr1/cmath.hpp>
  19. #include <boost/config.hpp>
  20. #include <boost/utility.hpp> // noncopyable
  21. #include <boost/integer_traits.hpp> // compile-time integral limits
  22. namespace boost {
  23. // use some OS service to generate non-deterministic random numbers
  24. class random_device : private noncopyable
  25. {
  26. public:
  27. typedef unsigned int result_type;
  28. BOOST_STATIC_CONSTANT(bool, has_fixed_range = true);
  29. BOOST_STATIC_CONSTANT(result_type, min_value = integer_traits<result_type>::const_min);
  30. BOOST_STATIC_CONSTANT(result_type, max_value = integer_traits<result_type>::const_max);
  31. result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return min_value; }
  32. result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return max_value; }
  33. explicit random_device(const std::string& token = default_token);
  34. ~random_device();
  35. double entropy() const;
  36. unsigned int operator()();
  37. private:
  38. static const char * const default_token;
  39. /*
  40. * std:5.3.5/5 [expr.delete]: "If the object being deleted has incomplete
  41. * class type at the point of deletion and the complete class has a
  42. * non-trivial destructor [...], the behavior is undefined".
  43. * This disallows the use of scoped_ptr<> with pimpl-like classes
  44. * having a non-trivial destructor.
  45. */
  46. class impl;
  47. impl * pimpl;
  48. };
  49. // TODO: put Schneier's Yarrow-160 algorithm here.
  50. } // namespace boost
  51. #endif /* BOOST_NONDET_RANDOM_HPP */