[12] | 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,v 1.9 2004/07/27 03:43:27 dgregor Exp $ |
---|
| 9 | * |
---|
| 10 | * Revision history |
---|
| 11 | * 2000-02-18 Portability fixes (thanks to Beman Dawes) |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | // See http://www.boost.org/libs/random for documentation. |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | #ifndef BOOST_NONDET_RANDOM_HPP |
---|
| 18 | #define BOOST_NONDET_RANDOM_HPP |
---|
| 19 | |
---|
| 20 | #include <string> // std::abs |
---|
| 21 | #include <algorithm> // std::min |
---|
| 22 | #include <cmath> |
---|
| 23 | #include <boost/config.hpp> |
---|
| 24 | #include <boost/utility.hpp> // noncopyable |
---|
| 25 | #include <boost/integer_traits.hpp> // compile-time integral limits |
---|
| 26 | |
---|
| 27 | namespace boost { |
---|
| 28 | |
---|
| 29 | // use some OS service to generate non-deterministic random numbers |
---|
| 30 | class random_device : private noncopyable |
---|
| 31 | { |
---|
| 32 | public: |
---|
| 33 | typedef unsigned int result_type; |
---|
| 34 | BOOST_STATIC_CONSTANT(bool, has_fixed_range = true); |
---|
| 35 | BOOST_STATIC_CONSTANT(result_type, min_value = integer_traits<result_type>::const_min); |
---|
| 36 | BOOST_STATIC_CONSTANT(result_type, max_value = integer_traits<result_type>::const_max); |
---|
| 37 | |
---|
| 38 | result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return min_value; } |
---|
| 39 | result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return max_value; } |
---|
| 40 | explicit random_device(const std::string& token = default_token); |
---|
| 41 | ~random_device(); |
---|
| 42 | double entropy() const; |
---|
| 43 | unsigned int operator()(); |
---|
| 44 | |
---|
| 45 | private: |
---|
| 46 | static const char * const default_token; |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * std:5.3.5/5 [expr.delete]: "If the object being deleted has incomplete |
---|
| 50 | * class type at the point of deletion and the complete class has a |
---|
| 51 | * non-trivial destructor [...], the behavior is undefined". |
---|
| 52 | * This disallows the use of scoped_ptr<> with pimpl-like classes |
---|
| 53 | * having a non-trivial destructor. |
---|
| 54 | */ |
---|
| 55 | class impl; |
---|
| 56 | impl * pimpl; |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | // TODO: put Schneier's Yarrow-160 algorithm here. |
---|
| 61 | |
---|
| 62 | } // namespace boost |
---|
| 63 | |
---|
| 64 | #endif /* BOOST_NONDET_RANDOM_HPP */ |
---|