annotate DEPENDENCIES/generic/include/boost/random/lagged_fibonacci.hpp @ 125:34e428693f5d vext

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