1 | /* boost random/random_number_generator.hpp header file |
---|
2 | * |
---|
3 | * Copyright Jens Maurer 2000-2001 |
---|
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 | * See http://www.boost.org for most recent version including documentation. |
---|
9 | * |
---|
10 | * $Id: random_number_generator.hpp,v 1.5 2004/11/09 21:22:00 jmaurer Exp $ |
---|
11 | * |
---|
12 | * Revision history |
---|
13 | * 2001-02-18 moved to individual header files |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP |
---|
17 | #define BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP |
---|
18 | |
---|
19 | #include <boost/config.hpp> |
---|
20 | #include <boost/limits.hpp> |
---|
21 | #include <boost/static_assert.hpp> |
---|
22 | #include <boost/random/uniform_int.hpp> |
---|
23 | #include <boost/random/variate_generator.hpp> |
---|
24 | |
---|
25 | namespace boost { |
---|
26 | |
---|
27 | // a model for RandomNumberGenerator std:25.2.11 [lib.alg.random.shuffle] |
---|
28 | template<class UniformRandomNumberGenerator, class IntType = long> |
---|
29 | class random_number_generator |
---|
30 | { |
---|
31 | public: |
---|
32 | typedef UniformRandomNumberGenerator base_type; |
---|
33 | typedef IntType argument_type; |
---|
34 | typedef IntType result_type; |
---|
35 | random_number_generator(base_type& rng) : _rng(rng) |
---|
36 | { |
---|
37 | #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS |
---|
38 | BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer); |
---|
39 | #endif |
---|
40 | } |
---|
41 | // compiler-generated copy ctor is fine |
---|
42 | // assignment is disallowed because there is a reference member |
---|
43 | |
---|
44 | result_type operator()(argument_type n) |
---|
45 | { |
---|
46 | typedef uniform_int<IntType> dist_type; |
---|
47 | return variate_generator<base_type&, dist_type>(_rng, dist_type(0, n-1))(); |
---|
48 | } |
---|
49 | |
---|
50 | private: |
---|
51 | base_type& _rng; |
---|
52 | }; |
---|
53 | |
---|
54 | } // namespace boost |
---|
55 | |
---|
56 | #endif // BOOST_RANDOM_RANDOM_NUMBER_GENERATOR_HPP |
---|