annotate DEPENDENCIES/generic/include/boost/random/lagged_fibonacci.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 /* boost random/lagged_fibonacci.hpp header file
Chris@16 2 *
Chris@16 3 * Copyright Jens Maurer 2000-2001
Chris@16 4 * Distributed under the Boost Software License, Version 1.0. (See
Chris@16 5 * accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 *
Chris@16 8 * See http://www.boost.org for most recent version including documentation.
Chris@16 9 *
Chris@16 10 * $Id: lagged_fibonacci.hpp 72951 2011-07-07 04:57:37Z steven_watanabe $
Chris@16 11 *
Chris@16 12 * Revision history
Chris@16 13 * 2001-02-18 moved to individual header files
Chris@16 14 */
Chris@16 15
Chris@16 16 #ifndef BOOST_RANDOM_LAGGED_FIBONACCI_HPP
Chris@16 17 #define BOOST_RANDOM_LAGGED_FIBONACCI_HPP
Chris@16 18
Chris@16 19 #include <istream>
Chris@16 20 #include <iosfwd>
Chris@16 21 #include <algorithm> // std::max
Chris@16 22 #include <iterator>
Chris@16 23 #include <boost/config/no_tr1/cmath.hpp> // std::pow
Chris@16 24 #include <boost/config.hpp>
Chris@16 25 #include <boost/limits.hpp>
Chris@16 26 #include <boost/cstdint.hpp>
Chris@16 27 #include <boost/integer/integer_mask.hpp>
Chris@16 28 #include <boost/random/linear_congruential.hpp>
Chris@16 29 #include <boost/random/uniform_01.hpp>
Chris@16 30 #include <boost/random/detail/config.hpp>
Chris@16 31 #include <boost/random/detail/seed.hpp>
Chris@16 32 #include <boost/random/detail/operators.hpp>
Chris@16 33 #include <boost/random/detail/generator_seed_seq.hpp>
Chris@16 34
Chris@16 35 namespace boost {
Chris@16 36 namespace random {
Chris@16 37
Chris@16 38 /**
Chris@16 39 * Instantiations of class template \lagged_fibonacci_engine model a
Chris@16 40 * \pseudo_random_number_generator. It uses a lagged Fibonacci
Chris@16 41 * algorithm with two lags @c p and @c q:
Chris@16 42 * x(i) = x(i-p) + x(i-q) (mod 2<sup>w</sup>) with p > q.
Chris@16 43 */
Chris@16 44 template<class UIntType, int w, unsigned int p, unsigned int q>
Chris@16 45 class lagged_fibonacci_engine
Chris@16 46 {
Chris@16 47 public:
Chris@16 48 typedef UIntType result_type;
Chris@16 49 BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
Chris@16 50 BOOST_STATIC_CONSTANT(int, word_size = w);
Chris@16 51 BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
Chris@16 52 BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
Chris@16 53
Chris@16 54 BOOST_STATIC_CONSTANT(UIntType, default_seed = 331u);
Chris@16 55
Chris@16 56 /** Returns the smallest value that the generator can produce. */
Chris@16 57 static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
Chris@16 58 /** Returns the largest value that the generator can produce. */
Chris@16 59 static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
Chris@16 60 { return low_bits_mask_t<w>::sig_bits; }
Chris@16 61
Chris@16 62 /** Creates a new @c lagged_fibonacci_engine and calls @c seed(). */
Chris@16 63 lagged_fibonacci_engine() { seed(); }
Chris@16 64
Chris@16 65 /** Creates a new @c lagged_fibonacci_engine and calls @c seed(value). */
Chris@16 66 BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_engine,
Chris@16 67 UIntType, value)
Chris@16 68 { seed(value); }
Chris@16 69
Chris@16 70 /** Creates a new @c lagged_fibonacci_engine and calls @c seed(seq). */
Chris@16 71 BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci_engine,
Chris@16 72 SeedSeq, seq)
Chris@16 73 { seed(seq); }
Chris@16 74
Chris@16 75 /**
Chris@16 76 * Creates a new @c lagged_fibonacci_engine and calls @c seed(first, last).
Chris@16 77 */
Chris@16 78 template<class It> lagged_fibonacci_engine(It& first, It last)
Chris@16 79 { seed(first, last); }
Chris@16 80
Chris@16 81 // compiler-generated copy ctor and assignment operator are fine
Chris@16 82
Chris@16 83 /** Calls @c seed(default_seed). */
Chris@16 84 void seed() { seed(default_seed); }
Chris@16 85
Chris@16 86 /**
Chris@16 87 * Sets the state of the generator to values produced by
Chris@16 88 * a \minstd_rand0 generator.
Chris@16 89 */
Chris@16 90 BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(lagged_fibonacci_engine,
Chris@16 91 UIntType, value)
Chris@16 92 {
Chris@16 93 minstd_rand0 intgen(static_cast<boost::uint32_t>(value));
Chris@16 94 detail::generator_seed_seq<minstd_rand0> gen(intgen);
Chris@16 95 seed(gen);
Chris@16 96 }
Chris@16 97
Chris@16 98 /**
Chris@16 99 * Sets the state of the generator using values produced by seq.
Chris@16 100 */
Chris@16 101 BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(lagged_fibonacci_engine, SeedSeq, seq)
Chris@16 102 {
Chris@16 103 detail::seed_array_int<w>(seq, x);
Chris@16 104 i = long_lag;
Chris@16 105 }
Chris@16 106
Chris@16 107 /**
Chris@16 108 * Sets the state of the generator to values from the iterator
Chris@16 109 * range [first, last). If there are not enough elements in the
Chris@16 110 * range [first, last) throws @c std::invalid_argument.
Chris@16 111 */
Chris@16 112 template<class It>
Chris@16 113 void seed(It& first, It last)
Chris@16 114 {
Chris@16 115 detail::fill_array_int<w>(first, last, x);
Chris@16 116 i = long_lag;
Chris@16 117 }
Chris@16 118
Chris@16 119 /** Returns the next value of the generator. */
Chris@16 120 result_type operator()()
Chris@16 121 {
Chris@16 122 if(i >= long_lag)
Chris@16 123 fill();
Chris@16 124 return x[i++];
Chris@16 125 }
Chris@16 126
Chris@16 127 /** Fills a range with random values */
Chris@16 128 template<class Iter>
Chris@16 129 void generate(Iter first, Iter last)
Chris@16 130 { detail::generate_from_int(*this, first, last); }
Chris@16 131
Chris@16 132 /** Advances the state of the generator by @c z. */
Chris@16 133 void discard(boost::uintmax_t z)
Chris@16 134 {
Chris@16 135 for(boost::uintmax_t j = 0; j < z; ++j) {
Chris@16 136 (*this)();
Chris@16 137 }
Chris@16 138 }
Chris@16 139
Chris@16 140 /**
Chris@16 141 * Writes the textual representation of the generator to a @c std::ostream.
Chris@16 142 */
Chris@16 143 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, lagged_fibonacci_engine, f)
Chris@16 144 {
Chris@16 145 os << f.i;
Chris@16 146 for(unsigned int i = 0; i < f.long_lag; ++i)
Chris@16 147 os << ' ' << f.x[i];
Chris@16 148 return os;
Chris@16 149 }
Chris@16 150
Chris@16 151 /**
Chris@16 152 * Reads the textual representation of the generator from a @c std::istream.
Chris@16 153 */
Chris@16 154 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, lagged_fibonacci_engine, f)
Chris@16 155 {
Chris@16 156 is >> f.i >> std::ws;
Chris@16 157 for(unsigned int i = 0; i < f.long_lag; ++i)
Chris@16 158 is >> f.x[i] >> std::ws;
Chris@16 159 return is;
Chris@16 160 }
Chris@16 161
Chris@16 162 /**
Chris@16 163 * Returns true if the two generators will produce identical
Chris@16 164 * sequences of outputs.
Chris@16 165 */
Chris@16 166 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(lagged_fibonacci_engine, x, y)
Chris@16 167 { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); }
Chris@16 168
Chris@16 169 /**
Chris@16 170 * Returns true if the two generators will produce different
Chris@16 171 * sequences of outputs.
Chris@16 172 */
Chris@16 173 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(lagged_fibonacci_engine)
Chris@16 174
Chris@16 175 private:
Chris@16 176 /// \cond show_private
Chris@16 177 void fill();
Chris@16 178 /// \endcond
Chris@16 179
Chris@16 180 unsigned int i;
Chris@16 181 UIntType x[long_lag];
Chris@16 182 };
Chris@16 183
Chris@16 184 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
Chris@16 185 // A definition is required even for integral static constants
Chris@16 186 template<class UIntType, int w, unsigned int p, unsigned int q>
Chris@16 187 const bool lagged_fibonacci_engine<UIntType, w, p, q>::has_fixed_range;
Chris@16 188 template<class UIntType, int w, unsigned int p, unsigned int q>
Chris@16 189 const unsigned int lagged_fibonacci_engine<UIntType, w, p, q>::long_lag;
Chris@16 190 template<class UIntType, int w, unsigned int p, unsigned int q>
Chris@16 191 const unsigned int lagged_fibonacci_engine<UIntType, w, p, q>::short_lag;
Chris@16 192 template<class UIntType, int w, unsigned int p, unsigned int q>
Chris@16 193 const UIntType lagged_fibonacci_engine<UIntType, w, p, q>::default_seed;
Chris@16 194 #endif
Chris@16 195
Chris@16 196 /// \cond show_private
Chris@16 197
Chris@16 198 template<class UIntType, int w, unsigned int p, unsigned int q>
Chris@16 199 void lagged_fibonacci_engine<UIntType, w, p, q>::fill()
Chris@16 200 {
Chris@16 201 // two loops to avoid costly modulo operations
Chris@16 202 { // extra scope for MSVC brokenness w.r.t. for scope
Chris@16 203 for(unsigned int j = 0; j < short_lag; ++j)
Chris@16 204 x[j] = (x[j] + x[j+(long_lag-short_lag)]) & low_bits_mask_t<w>::sig_bits;
Chris@16 205 }
Chris@16 206 for(unsigned int j = short_lag; j < long_lag; ++j)
Chris@16 207 x[j] = (x[j] + x[j-short_lag]) & low_bits_mask_t<w>::sig_bits;
Chris@16 208 i = 0;
Chris@16 209 }
Chris@16 210
Chris@16 211 /// \endcond
Chris@16 212
Chris@16 213 /// \cond show_deprecated
Chris@16 214
Chris@16 215 // provided for backwards compatibility
Chris@16 216 template<class UIntType, int w, unsigned int p, unsigned int q, UIntType v = 0>
Chris@16 217 class lagged_fibonacci : public lagged_fibonacci_engine<UIntType, w, p, q>
Chris@16 218 {
Chris@16 219 typedef lagged_fibonacci_engine<UIntType, w, p, q> base_type;
Chris@16 220 public:
Chris@16 221 lagged_fibonacci() {}
Chris@16 222 BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci, UIntType, val)
Chris@16 223 { this->seed(val); }
Chris@16 224 BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci, SeedSeq, seq)
Chris@16 225 { this->seed(seq); }
Chris@16 226 template<class It>
Chris@16 227 lagged_fibonacci(It& first, It last) : base_type(first, last) {}
Chris@16 228 };
Chris@16 229
Chris@16 230 /// \endcond
Chris@16 231
Chris@16 232 // lagged Fibonacci generator for the range [0..1)
Chris@16 233 // contributed by Matthias Troyer
Chris@16 234 // for p=55, q=24 originally by G. J. Mitchell and D. P. Moore 1958
Chris@16 235
Chris@16 236 /**
Chris@16 237 * Instantiations of class template @c lagged_fibonacci_01 model a
Chris@16 238 * \pseudo_random_number_generator. It uses a lagged Fibonacci
Chris@16 239 * algorithm with two lags @c p and @c q, evaluated in floating-point
Chris@16 240 * arithmetic: x(i) = x(i-p) + x(i-q) (mod 1) with p > q. See
Chris@16 241 *
Chris@16 242 * @blockquote
Chris@16 243 * "Uniform random number generators for supercomputers", Richard Brent,
Chris@16 244 * Proc. of Fifth Australian Supercomputer Conference, Melbourne,
Chris@16 245 * Dec. 1992, pp. 704-706.
Chris@16 246 * @endblockquote
Chris@16 247 *
Chris@16 248 * @xmlnote
Chris@16 249 * The quality of the generator crucially depends on the choice
Chris@16 250 * of the parameters. User code should employ one of the sensibly
Chris@16 251 * parameterized generators such as \lagged_fibonacci607 instead.
Chris@16 252 * @endxmlnote
Chris@16 253 *
Chris@16 254 * The generator requires considerable amounts of memory for the storage
Chris@16 255 * of its state array. For example, \lagged_fibonacci607 requires about
Chris@16 256 * 4856 bytes and \lagged_fibonacci44497 requires about 350 KBytes.
Chris@16 257 */
Chris@16 258 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 259 class lagged_fibonacci_01_engine
Chris@16 260 {
Chris@16 261 public:
Chris@16 262 typedef RealType result_type;
Chris@16 263 BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
Chris@16 264 BOOST_STATIC_CONSTANT(int, word_size = w);
Chris@16 265 BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
Chris@16 266 BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
Chris@16 267
Chris@16 268 BOOST_STATIC_CONSTANT(boost::uint32_t, default_seed = 331u);
Chris@16 269
Chris@16 270 /** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(). */
Chris@16 271 lagged_fibonacci_01_engine() { seed(); }
Chris@16 272 /** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(value). */
Chris@16 273 BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_01_engine, uint32_t, value)
Chris@16 274 { seed(value); }
Chris@16 275 /** Constructs a @c lagged_fibonacci_01 generator and calls @c seed(gen). */
Chris@16 276 BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci_01_engine, SeedSeq, seq)
Chris@16 277 { seed(seq); }
Chris@16 278 template<class It> lagged_fibonacci_01_engine(It& first, It last)
Chris@16 279 { seed(first, last); }
Chris@16 280
Chris@16 281 // compiler-generated copy ctor and assignment operator are fine
Chris@16 282
Chris@16 283 /** Calls seed(default_seed). */
Chris@16 284 void seed() { seed(default_seed); }
Chris@16 285
Chris@16 286 /**
Chris@16 287 * Constructs a \minstd_rand0 generator with the constructor parameter
Chris@16 288 * value and calls seed with it. Distinct seeds in the range
Chris@16 289 * [1, 2147483647) will produce generators with different states. Other
Chris@16 290 * seeds will be equivalent to some seed within this range. See
Chris@16 291 * \linear_congruential_engine for details.
Chris@16 292 */
Chris@16 293 BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(lagged_fibonacci_01_engine, boost::uint32_t, value)
Chris@16 294 {
Chris@16 295 minstd_rand0 intgen(value);
Chris@16 296 detail::generator_seed_seq<minstd_rand0> gen(intgen);
Chris@16 297 seed(gen);
Chris@16 298 }
Chris@16 299
Chris@16 300 /**
Chris@16 301 * Seeds this @c lagged_fibonacci_01_engine using values produced by
Chris@16 302 * @c seq.generate.
Chris@16 303 */
Chris@16 304 BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(lagged_fibonacci_01_engine, SeedSeq, seq)
Chris@16 305 {
Chris@16 306 detail::seed_array_real<w>(seq, x);
Chris@16 307 i = long_lag;
Chris@16 308 }
Chris@16 309
Chris@16 310 /**
Chris@16 311 * Seeds this @c lagged_fibonacci_01_engine using values from the
Chris@16 312 * iterator range [first, last). If there are not enough elements
Chris@16 313 * in the range, throws @c std::invalid_argument.
Chris@16 314 */
Chris@16 315 template<class It>
Chris@16 316 void seed(It& first, It last)
Chris@16 317 {
Chris@16 318 detail::fill_array_real<w>(first, last, x);
Chris@16 319 i = long_lag;
Chris@16 320 }
Chris@16 321
Chris@16 322 /** Returns the smallest value that the generator can produce. */
Chris@16 323 static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return result_type(0); }
Chris@16 324 /** Returns the upper bound of the generators outputs. */
Chris@16 325 static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () { return result_type(1); }
Chris@16 326
Chris@16 327 /** Returns the next value of the generator. */
Chris@16 328 result_type operator()()
Chris@16 329 {
Chris@16 330 if(i >= long_lag)
Chris@16 331 fill();
Chris@16 332 return x[i++];
Chris@16 333 }
Chris@16 334
Chris@16 335 /** Fills a range with random values */
Chris@16 336 template<class Iter>
Chris@16 337 void generate(Iter first, Iter last)
Chris@16 338 { return detail::generate_from_real(*this, first, last); }
Chris@16 339
Chris@16 340 /** Advances the state of the generator by @c z. */
Chris@16 341 void discard(boost::uintmax_t z)
Chris@16 342 {
Chris@16 343 for(boost::uintmax_t j = 0; j < z; ++j) {
Chris@16 344 (*this)();
Chris@16 345 }
Chris@16 346 }
Chris@16 347
Chris@16 348 /**
Chris@16 349 * Writes the textual representation of the generator to a @c std::ostream.
Chris@16 350 */
Chris@16 351 BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, lagged_fibonacci_01_engine, f)
Chris@16 352 {
Chris@16 353 // allow for Koenig lookup
Chris@16 354 using std::pow;
Chris@16 355 os << f.i;
Chris@16 356 std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left);
Chris@16 357 for(unsigned int i = 0; i < f.long_lag; ++i)
Chris@16 358 os << ' ' << f.x[i] * f.modulus();
Chris@16 359 os.flags(oldflags);
Chris@16 360 return os;
Chris@16 361 }
Chris@16 362
Chris@16 363 /**
Chris@16 364 * Reads the textual representation of the generator from a @c std::istream.
Chris@16 365 */
Chris@16 366 BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, lagged_fibonacci_01_engine, f)
Chris@16 367 {
Chris@16 368 is >> f.i;
Chris@16 369 for(unsigned int i = 0; i < f.long_lag; ++i) {
Chris@16 370 typename lagged_fibonacci_01_engine::result_type value;
Chris@16 371 is >> std::ws >> value;
Chris@16 372 f.x[i] = value / f.modulus();
Chris@16 373 }
Chris@16 374 return is;
Chris@16 375 }
Chris@16 376
Chris@16 377 /**
Chris@16 378 * Returns true if the two generators will produce identical
Chris@16 379 * sequences of outputs.
Chris@16 380 */
Chris@16 381 BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(lagged_fibonacci_01_engine, x, y)
Chris@16 382 { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); }
Chris@16 383
Chris@16 384 /**
Chris@16 385 * Returns true if the two generators will produce different
Chris@16 386 * sequences of outputs.
Chris@16 387 */
Chris@16 388 BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(lagged_fibonacci_01_engine)
Chris@16 389
Chris@16 390 private:
Chris@16 391 /// \cond show_private
Chris@16 392 void fill();
Chris@16 393 static RealType modulus()
Chris@16 394 {
Chris@16 395 using std::pow;
Chris@16 396 return pow(RealType(2), word_size);
Chris@16 397 }
Chris@16 398 /// \endcond
Chris@16 399 unsigned int i;
Chris@16 400 RealType x[long_lag];
Chris@16 401 };
Chris@16 402
Chris@16 403 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
Chris@16 404 // A definition is required even for integral static constants
Chris@16 405 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 406 const bool lagged_fibonacci_01_engine<RealType, w, p, q>::has_fixed_range;
Chris@16 407 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 408 const unsigned int lagged_fibonacci_01_engine<RealType, w, p, q>::long_lag;
Chris@16 409 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 410 const unsigned int lagged_fibonacci_01_engine<RealType, w, p, q>::short_lag;
Chris@16 411 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 412 const int lagged_fibonacci_01_engine<RealType,w,p,q>::word_size;
Chris@16 413 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 414 const boost::uint32_t lagged_fibonacci_01_engine<RealType,w,p,q>::default_seed;
Chris@16 415 #endif
Chris@16 416
Chris@16 417 /// \cond show_private
Chris@16 418 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 419 void lagged_fibonacci_01_engine<RealType, w, p, q>::fill()
Chris@16 420 {
Chris@16 421 // two loops to avoid costly modulo operations
Chris@16 422 { // extra scope for MSVC brokenness w.r.t. for scope
Chris@16 423 for(unsigned int j = 0; j < short_lag; ++j) {
Chris@16 424 RealType t = x[j] + x[j+(long_lag-short_lag)];
Chris@16 425 if(t >= RealType(1))
Chris@16 426 t -= RealType(1);
Chris@16 427 x[j] = t;
Chris@16 428 }
Chris@16 429 }
Chris@16 430 for(unsigned int j = short_lag; j < long_lag; ++j) {
Chris@16 431 RealType t = x[j] + x[j-short_lag];
Chris@16 432 if(t >= RealType(1))
Chris@16 433 t -= RealType(1);
Chris@16 434 x[j] = t;
Chris@16 435 }
Chris@16 436 i = 0;
Chris@16 437 }
Chris@16 438 /// \endcond
Chris@16 439
Chris@16 440 /// \cond show_deprecated
Chris@16 441
Chris@16 442 // provided for backwards compatibility
Chris@16 443 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 444 class lagged_fibonacci_01 : public lagged_fibonacci_01_engine<RealType, w, p, q>
Chris@16 445 {
Chris@16 446 typedef lagged_fibonacci_01_engine<RealType, w, p, q> base_type;
Chris@16 447 public:
Chris@16 448 lagged_fibonacci_01() {}
Chris@16 449 BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(lagged_fibonacci_01, boost::uint32_t, val)
Chris@16 450 { this->seed(val); }
Chris@16 451 BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(lagged_fibonacci_01, SeedSeq, seq)
Chris@16 452 { this->seed(seq); }
Chris@16 453 template<class It>
Chris@16 454 lagged_fibonacci_01(It& first, It last) : base_type(first, last) {}
Chris@16 455 };
Chris@16 456
Chris@16 457 /// \endcond
Chris@16 458
Chris@16 459 namespace detail {
Chris@16 460
Chris@16 461 template<class Engine>
Chris@16 462 struct generator_bits;
Chris@16 463
Chris@16 464 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 465 struct generator_bits<lagged_fibonacci_01_engine<RealType, w, p, q> >
Chris@16 466 {
Chris@16 467 static std::size_t value() { return w; }
Chris@16 468 };
Chris@16 469
Chris@16 470 template<class RealType, int w, unsigned int p, unsigned int q>
Chris@16 471 struct generator_bits<lagged_fibonacci_01<RealType, w, p, q> >
Chris@16 472 {
Chris@16 473 static std::size_t value() { return w; }
Chris@16 474 };
Chris@16 475
Chris@16 476 }
Chris@16 477
Chris@16 478 #ifdef BOOST_RANDOM_DOXYGEN
Chris@16 479 namespace detail {
Chris@16 480 /**
Chris@16 481 * The specializations lagged_fibonacci607 ... lagged_fibonacci44497
Chris@16 482 * use well tested lags.
Chris@16 483 *
Chris@16 484 * See
Chris@16 485 *
Chris@16 486 * @blockquote
Chris@16 487 * "On the Periods of Generalized Fibonacci Recurrences", Richard P. Brent
Chris@16 488 * Computer Sciences Laboratory Australian National University, December 1992
Chris@16 489 * @endblockquote
Chris@16 490 *
Chris@16 491 * The lags used here can be found in
Chris@16 492 *
Chris@16 493 * @blockquote
Chris@16 494 * "Uniform random number generators for supercomputers", Richard Brent,
Chris@16 495 * Proc. of Fifth Australian Supercomputer Conference, Melbourne,
Chris@16 496 * Dec. 1992, pp. 704-706.
Chris@16 497 * @endblockquote
Chris@16 498 */
Chris@16 499 struct lagged_fibonacci_doc {};
Chris@16 500 }
Chris@16 501 #endif
Chris@16 502
Chris@16 503 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 504 typedef lagged_fibonacci_01_engine<double, 48, 607, 273> lagged_fibonacci607;
Chris@16 505 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 506 typedef lagged_fibonacci_01_engine<double, 48, 1279, 418> lagged_fibonacci1279;
Chris@16 507 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 508 typedef lagged_fibonacci_01_engine<double, 48, 2281, 1252> lagged_fibonacci2281;
Chris@16 509 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 510 typedef lagged_fibonacci_01_engine<double, 48, 3217, 576> lagged_fibonacci3217;
Chris@16 511 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 512 typedef lagged_fibonacci_01_engine<double, 48, 4423, 2098> lagged_fibonacci4423;
Chris@16 513 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 514 typedef lagged_fibonacci_01_engine<double, 48, 9689, 5502> lagged_fibonacci9689;
Chris@16 515 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 516 typedef lagged_fibonacci_01_engine<double, 48, 19937, 9842> lagged_fibonacci19937;
Chris@16 517 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 518 typedef lagged_fibonacci_01_engine<double, 48, 23209, 13470> lagged_fibonacci23209;
Chris@16 519 /** @copydoc boost::random::detail::lagged_fibonacci_doc */
Chris@16 520 typedef lagged_fibonacci_01_engine<double, 48, 44497, 21034> lagged_fibonacci44497;
Chris@16 521
Chris@16 522 } // namespace random
Chris@16 523
Chris@16 524 using random::lagged_fibonacci607;
Chris@16 525 using random::lagged_fibonacci1279;
Chris@16 526 using random::lagged_fibonacci2281;
Chris@16 527 using random::lagged_fibonacci3217;
Chris@16 528 using random::lagged_fibonacci4423;
Chris@16 529 using random::lagged_fibonacci9689;
Chris@16 530 using random::lagged_fibonacci19937;
Chris@16 531 using random::lagged_fibonacci23209;
Chris@16 532 using random::lagged_fibonacci44497;
Chris@16 533
Chris@16 534 } // namespace boost
Chris@16 535
Chris@16 536 #endif // BOOST_RANDOM_LAGGED_FIBONACCI_HPP