3 * Copyright Jens Maurer 2000, 2002
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)
14 * NOTE: This is not part of the official boost submission. It exists
15 * only as a collection of ideas.
18 #ifndef BOOST_RANDOM_HAERTEL_HPP
19 #define BOOST_RANDOM_HAERTEL_HPP
21 #include <boost/cstdint.hpp>
22 #include <boost/random/linear_congruential.hpp>
23 #include <boost/random/inversive_congruential.hpp>
28 // Wikramaratna 1989 ACORN
29 template<class IntType, int k, IntType m, IntType val>
30 class additive_congruential
33 typedef IntType result_type;
34 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
35 static const bool has_fixed_range = true;
36 static const result_type min_value = 0;
37 static const result_type max_value = m-1;
40 has_fixed_range = true,
45 template<class InputIterator>
46 explicit additive_congruential(InputIterator start) { seed(start); }
47 template<class InputIterator>
48 void seed(InputIterator start)
50 for(int i = 0; i <= k; ++i, ++start)
54 result_type operator()()
56 for(int i = 1; i <= k; ++i) {
57 IntType tmp = values[i-1] + values[i];
64 result_type validation() const { return val; }
70 template<class IntType, int r, int s, IntType m, IntType val>
71 class lagged_fibonacci_int
74 typedef IntType result_type;
75 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
76 static const bool has_fixed_range = true;
77 static const result_type min_value = 0;
78 static const result_type max_value = m-1;
81 has_fixed_range = true,
86 explicit lagged_fibonacci_int(IntType start) { seed(start); }
87 template<class Generator>
88 explicit lagged_fibonacci_int(Generator & gen) { seed(gen); }
89 void seed(IntType start)
91 linear_congruential<uint32_t, 299375077, 0, 0, 0> init;
94 template<class Generator>
95 void seed(Generator & gen)
98 for(int i = 0; i < 607; ++i)
104 result_type operator()()
106 result_type tmp = values[current] + values[lag];
109 values[current] = tmp;
118 result_type validation() const { return val; }
120 result_type values[r];
124 } // namespace random
127 // distributions from Haertel's dissertation
128 // (additional parameterizations of the basic templates)
130 typedef boost::random::linear_congruential<boost::uint64_t, 45965, 453816691,
131 (boost::uint64_t(1)<<31), 0> LCG_Af2;
132 typedef boost::random::linear_congruential<boost::uint64_t, 211936855, 0,
133 (boost::uint64_t(1)<<29)-3, 0> LCG_Die1;
134 typedef boost::random::linear_congruential<boost::uint32_t, 2824527309u, 0,
136 typedef boost::random::linear_congruential<boost::uint64_t, 950706376u, 0,
137 (boost::uint64_t(1)<<31)-1, 0> LCG_FM;
138 typedef boost::random::linear_congruential<boost::int32_t, 51081, 0,
139 2147483647, 0> LCG_Hae;
140 typedef boost::random::linear_congruential<boost::uint32_t, 69069, 1,
142 typedef boost::random::inversive_congruential<boost::int64_t, 240318, 197,
143 1000081, 0> NLG_Inv1;
144 typedef boost::random::inversive_congruential<boost::int64_t, 15707262,
145 13262967, (1<<24)-17, 0> NLG_Inv2;
146 typedef boost::random::inversive_congruential<boost::int32_t, 1, 1,
147 2147483647, 0> NLG_Inv4;
148 typedef boost::random::inversive_congruential<boost::int32_t, 1, 2,
150 typedef boost::random::additive_congruential<boost::int32_t, 6,
151 (1<<30)-35, 0> MRG_Acorn7;
152 typedef boost::random::lagged_fibonacci_int<boost::uint32_t, 607, 273,
154 } // namespace Haertel