os/ossrv/ossrv_pub/boost_apis/boost/random/lagged_fibonacci.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* boost random/lagged_fibonacci.hpp header file
sl@0
     2
 *
sl@0
     3
 * Copyright Jens Maurer 2000-2001
sl@0
     4
 * Distributed under the Boost Software License, Version 1.0. (See
sl@0
     5
 * accompanying file LICENSE_1_0.txt or copy at
sl@0
     6
 * http://www.boost.org/LICENSE_1_0.txt)
sl@0
     7
 *
sl@0
     8
 * See http://www.boost.org for most recent version including documentation.
sl@0
     9
 *
sl@0
    10
 * $Id: lagged_fibonacci.hpp,v 1.28 2005/05/21 15:57:00 dgregor Exp $
sl@0
    11
 *
sl@0
    12
 * Revision history
sl@0
    13
 *  2001-02-18  moved to individual header files
sl@0
    14
 */
sl@0
    15
sl@0
    16
#ifndef BOOST_RANDOM_LAGGED_FIBONACCI_HPP
sl@0
    17
#define BOOST_RANDOM_LAGGED_FIBONACCI_HPP
sl@0
    18
sl@0
    19
#include <cmath>
sl@0
    20
#include <iostream>
sl@0
    21
#include <algorithm>     // std::max
sl@0
    22
#include <iterator>
sl@0
    23
#include <cmath>         // std::pow
sl@0
    24
#include <boost/config.hpp>
sl@0
    25
#include <boost/limits.hpp>
sl@0
    26
#include <boost/cstdint.hpp>
sl@0
    27
#include <boost/detail/workaround.hpp>
sl@0
    28
#include <boost/random/linear_congruential.hpp>
sl@0
    29
#include <boost/random/uniform_01.hpp>
sl@0
    30
#include <boost/random/detail/pass_through_engine.hpp>
sl@0
    31
sl@0
    32
namespace boost {
sl@0
    33
namespace random {
sl@0
    34
sl@0
    35
#if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300
sl@0
    36
#  define BOOST_RANDOM_EXTRACT_LF
sl@0
    37
#endif
sl@0
    38
sl@0
    39
#if defined(__APPLE_CC__) && defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ <= 3)
sl@0
    40
#  define BOOST_RANDOM_EXTRACT_LF
sl@0
    41
#endif
sl@0
    42
sl@0
    43
#  ifdef BOOST_RANDOM_EXTRACT_LF
sl@0
    44
namespace detail
sl@0
    45
{
sl@0
    46
  template<class IStream, class F, class RealType>
sl@0
    47
  IStream&
sl@0
    48
  extract_lagged_fibonacci_01(
sl@0
    49
      IStream& is
sl@0
    50
      , F const& f
sl@0
    51
      , unsigned int& i
sl@0
    52
      , RealType* x
sl@0
    53
      , RealType modulus)
sl@0
    54
  {
sl@0
    55
        is >> i >> std::ws;
sl@0
    56
        for(unsigned int i = 0; i < f.long_lag; ++i)
sl@0
    57
        {
sl@0
    58
            RealType value;
sl@0
    59
            is >> value >> std::ws;
sl@0
    60
            x[i] = value / modulus;
sl@0
    61
        }
sl@0
    62
        return is;
sl@0
    63
  }
sl@0
    64
sl@0
    65
  template<class IStream, class F, class UIntType>
sl@0
    66
  IStream&
sl@0
    67
  extract_lagged_fibonacci(
sl@0
    68
      IStream& is
sl@0
    69
      , F const& f
sl@0
    70
      , unsigned int& i
sl@0
    71
      , UIntType* x)
sl@0
    72
  {
sl@0
    73
      is >> i >> std::ws;
sl@0
    74
      for(unsigned int i = 0; i < f.long_lag; ++i)
sl@0
    75
          is >> x[i] >> std::ws;
sl@0
    76
      return is;
sl@0
    77
  }
sl@0
    78
}
sl@0
    79
#  endif
sl@0
    80
sl@0
    81
template<class UIntType, int w, unsigned int p, unsigned int q,
sl@0
    82
         UIntType val = 0>
sl@0
    83
class lagged_fibonacci
sl@0
    84
{
sl@0
    85
public:
sl@0
    86
  typedef UIntType result_type;
sl@0
    87
  BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
sl@0
    88
  BOOST_STATIC_CONSTANT(int, word_size = w);
sl@0
    89
  BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
sl@0
    90
  BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
sl@0
    91
sl@0
    92
  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
sl@0
    93
  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return wordmask; }
sl@0
    94
sl@0
    95
  lagged_fibonacci() { init_wordmask(); seed(); }
sl@0
    96
  explicit lagged_fibonacci(uint32_t value) { init_wordmask(); seed(value); }
sl@0
    97
  template<class It> lagged_fibonacci(It& first, It last)
sl@0
    98
  { init_wordmask(); seed(first, last); }
sl@0
    99
  // compiler-generated copy ctor and assignment operator are fine
sl@0
   100
sl@0
   101
private:
sl@0
   102
  void init_wordmask()
sl@0
   103
  {
sl@0
   104
    wordmask = 0;
sl@0
   105
    for(int i = 0; i < w; ++i)
sl@0
   106
      wordmask |= (1u << i);
sl@0
   107
  }
sl@0
   108
sl@0
   109
public:
sl@0
   110
  void seed(uint32_t value = 331u)
sl@0
   111
  {
sl@0
   112
    minstd_rand0 gen(value);
sl@0
   113
    for(unsigned int j = 0; j < long_lag; ++j)
sl@0
   114
      x[j] = gen() & wordmask;
sl@0
   115
    i = long_lag;
sl@0
   116
  }
sl@0
   117
sl@0
   118
  template<class It>
sl@0
   119
  void seed(It& first, It last)
sl@0
   120
  {
sl@0
   121
    // word size could be smaller than the seed values
sl@0
   122
    unsigned int j;
sl@0
   123
    for(j = 0; j < long_lag && first != last; ++j, ++first)
sl@0
   124
      x[j] = *first & wordmask;
sl@0
   125
    i = long_lag;
sl@0
   126
    if(first == last && j < long_lag)
sl@0
   127
      throw std::invalid_argument("lagged_fibonacci::seed");
sl@0
   128
  }
sl@0
   129
sl@0
   130
  result_type operator()()
sl@0
   131
  {
sl@0
   132
    if(i >= long_lag)
sl@0
   133
      fill();
sl@0
   134
    return x[i++];
sl@0
   135
  }
sl@0
   136
sl@0
   137
  static bool validation(result_type x)
sl@0
   138
  {
sl@0
   139
    return x == val;
sl@0
   140
  }
sl@0
   141
  
sl@0
   142
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
sl@0
   143
sl@0
   144
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
sl@0
   145
  template<class CharT, class Traits>
sl@0
   146
  friend std::basic_ostream<CharT,Traits>&
sl@0
   147
  operator<<(std::basic_ostream<CharT,Traits>& os, const lagged_fibonacci& f)
sl@0
   148
  {
sl@0
   149
    os << f.i << " ";
sl@0
   150
    for(unsigned int i = 0; i < f.long_lag; ++i)
sl@0
   151
      os << f.x[i] << " ";
sl@0
   152
    return os;
sl@0
   153
  }
sl@0
   154
sl@0
   155
  template<class CharT, class Traits>
sl@0
   156
  friend std::basic_istream<CharT, Traits>&
sl@0
   157
  operator>>(std::basic_istream<CharT, Traits>& is, lagged_fibonacci& f)
sl@0
   158
  {
sl@0
   159
# ifdef BOOST_RANDOM_EXTRACT_LF
sl@0
   160
      return detail::extract_lagged_fibonacci(is, f, f.i, f.x);
sl@0
   161
# else
sl@0
   162
      is >> f.i >> std::ws;
sl@0
   163
      for(unsigned int i = 0; i < f.long_lag; ++i)
sl@0
   164
          is >> f.x[i] >> std::ws;
sl@0
   165
      return is;
sl@0
   166
# endif 
sl@0
   167
  }
sl@0
   168
#endif
sl@0
   169
sl@0
   170
  friend bool operator==(const lagged_fibonacci& x, const lagged_fibonacci& y)
sl@0
   171
  { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); }
sl@0
   172
  friend bool operator!=(const lagged_fibonacci& x,
sl@0
   173
                         const lagged_fibonacci& y)
sl@0
   174
  { return !(x == y); }
sl@0
   175
#else
sl@0
   176
  // Use a member function; Streamable concept not supported.
sl@0
   177
  bool operator==(const lagged_fibonacci& rhs) const
sl@0
   178
  { return i == rhs.i && std::equal(x, x+long_lag, rhs.x); }
sl@0
   179
  bool operator!=(const lagged_fibonacci& rhs) const
sl@0
   180
  { return !(*this == rhs); }
sl@0
   181
#endif
sl@0
   182
sl@0
   183
private:
sl@0
   184
  void fill();
sl@0
   185
  UIntType wordmask;
sl@0
   186
  unsigned int i;
sl@0
   187
  UIntType x[long_lag];
sl@0
   188
};
sl@0
   189
sl@0
   190
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
sl@0
   191
//  A definition is required even for integral static constants
sl@0
   192
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
sl@0
   193
const bool lagged_fibonacci<UIntType, w, p, q, val>::has_fixed_range;
sl@0
   194
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
sl@0
   195
const unsigned int lagged_fibonacci<UIntType, w, p, q, val>::long_lag;
sl@0
   196
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
sl@0
   197
const unsigned int lagged_fibonacci<UIntType, w, p, q, val>::short_lag;
sl@0
   198
#endif
sl@0
   199
sl@0
   200
template<class UIntType, int w, unsigned int p, unsigned int q, UIntType val>
sl@0
   201
void lagged_fibonacci<UIntType, w, p, q, val>::fill()
sl@0
   202
{
sl@0
   203
  // two loops to avoid costly modulo operations
sl@0
   204
  {  // extra scope for MSVC brokenness w.r.t. for scope
sl@0
   205
  for(unsigned int j = 0; j < short_lag; ++j)
sl@0
   206
    x[j] = (x[j] + x[j+(long_lag-short_lag)]) & wordmask;
sl@0
   207
  }
sl@0
   208
  for(unsigned int j = short_lag; j < long_lag; ++j)
sl@0
   209
    x[j] = (x[j] + x[j-short_lag]) & wordmask;
sl@0
   210
  i = 0;
sl@0
   211
}
sl@0
   212
sl@0
   213
sl@0
   214
sl@0
   215
// lagged Fibonacci generator for the range [0..1)
sl@0
   216
// contributed by Matthias Troyer
sl@0
   217
// for p=55, q=24 originally by G. J. Mitchell and D. P. Moore 1958
sl@0
   218
sl@0
   219
template<class T, unsigned int p, unsigned int q>
sl@0
   220
struct fibonacci_validation
sl@0
   221
{
sl@0
   222
  BOOST_STATIC_CONSTANT(bool, is_specialized = false);
sl@0
   223
  static T value() { return 0; }
sl@0
   224
  static T tolerance() { return 0; }
sl@0
   225
};
sl@0
   226
sl@0
   227
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
sl@0
   228
//  A definition is required even for integral static constants
sl@0
   229
template<class T, unsigned int p, unsigned int q>
sl@0
   230
const bool fibonacci_validation<T, p, q>::is_specialized;
sl@0
   231
#endif
sl@0
   232
sl@0
   233
#define BOOST_RANDOM_FIBONACCI_VAL(T,P,Q,V,E) \
sl@0
   234
template<> \
sl@0
   235
struct fibonacci_validation<T, P, Q>  \
sl@0
   236
{                                     \
sl@0
   237
  BOOST_STATIC_CONSTANT(bool, is_specialized = true);     \
sl@0
   238
  static T value() { return V; }      \
sl@0
   239
  static T tolerance()                \
sl@0
   240
{ return (std::max)(E, static_cast<T>(5*std::numeric_limits<T>::epsilon())); } \
sl@0
   241
};
sl@0
   242
// (The extra static_cast<T> in the std::max call above is actually
sl@0
   243
// unnecessary except for HP aCC 1.30, which claims that
sl@0
   244
// numeric_limits<double>::epsilon() doesn't actually return a double.)
sl@0
   245
sl@0
   246
BOOST_RANDOM_FIBONACCI_VAL(double, 607, 273, 0.4293817707235914, 1e-14)
sl@0
   247
BOOST_RANDOM_FIBONACCI_VAL(double, 1279, 418, 0.9421630240437659, 1e-14)
sl@0
   248
BOOST_RANDOM_FIBONACCI_VAL(double, 2281, 1252, 0.1768114046909004, 1e-14)
sl@0
   249
BOOST_RANDOM_FIBONACCI_VAL(double, 3217, 576, 0.1956232694868209, 1e-14)
sl@0
   250
BOOST_RANDOM_FIBONACCI_VAL(double, 4423, 2098, 0.9499762202147172, 1e-14)
sl@0
   251
BOOST_RANDOM_FIBONACCI_VAL(double, 9689, 5502, 0.05737836943695162, 1e-14)
sl@0
   252
BOOST_RANDOM_FIBONACCI_VAL(double, 19937, 9842, 0.5076528587449834, 1e-14)
sl@0
   253
BOOST_RANDOM_FIBONACCI_VAL(double, 23209, 13470, 0.5414473810619185, 1e-14)
sl@0
   254
BOOST_RANDOM_FIBONACCI_VAL(double, 44497,21034, 0.254135073399297, 1e-14)
sl@0
   255
sl@0
   256
#undef BOOST_RANDOM_FIBONACCI_VAL
sl@0
   257
sl@0
   258
template<class RealType, int w, unsigned int p, unsigned int q>
sl@0
   259
class lagged_fibonacci_01
sl@0
   260
{
sl@0
   261
public:
sl@0
   262
  typedef RealType result_type;
sl@0
   263
  BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
sl@0
   264
  BOOST_STATIC_CONSTANT(int, word_size = w);
sl@0
   265
  BOOST_STATIC_CONSTANT(unsigned int, long_lag = p);
sl@0
   266
  BOOST_STATIC_CONSTANT(unsigned int, short_lag = q);
sl@0
   267
sl@0
   268
  lagged_fibonacci_01() { init_modulus(); seed(); }
sl@0
   269
  explicit lagged_fibonacci_01(uint32_t value) { init_modulus(); seed(value); }
sl@0
   270
  template<class Generator>
sl@0
   271
  explicit lagged_fibonacci_01(Generator & gen) { init_modulus(); seed(gen); }
sl@0
   272
  template<class It> lagged_fibonacci_01(It& first, It last)
sl@0
   273
  { init_modulus(); seed(first, last); }
sl@0
   274
  // compiler-generated copy ctor and assignment operator are fine
sl@0
   275
sl@0
   276
private:
sl@0
   277
  void init_modulus()
sl@0
   278
  {
sl@0
   279
#ifndef BOOST_NO_STDC_NAMESPACE
sl@0
   280
    // allow for Koenig lookup
sl@0
   281
    using std::pow;
sl@0
   282
#endif
sl@0
   283
    _modulus = pow(RealType(2), word_size);
sl@0
   284
  }
sl@0
   285
sl@0
   286
public:
sl@0
   287
  void seed(uint32_t value = 331u)
sl@0
   288
  {
sl@0
   289
    minstd_rand0 intgen(value);
sl@0
   290
    seed(intgen);
sl@0
   291
  }
sl@0
   292
sl@0
   293
  // For GCC, moving this function out-of-line prevents inlining, which may
sl@0
   294
  // reduce overall object code size.  However, MSVC does not grok
sl@0
   295
  // out-of-line template member functions.
sl@0
   296
  template<class Generator>
sl@0
   297
  void seed(Generator & gen)
sl@0
   298
  {
sl@0
   299
    // use pass-by-reference, but wrap argument in pass_through_engine
sl@0
   300
    typedef detail::pass_through_engine<Generator&> ref_gen;
sl@0
   301
    uniform_01<ref_gen, RealType> gen01 =
sl@0
   302
      uniform_01<ref_gen, RealType>(ref_gen(gen));
sl@0
   303
    // I could have used std::generate_n, but it takes "gen" by value
sl@0
   304
    for(unsigned int j = 0; j < long_lag; ++j)
sl@0
   305
      x[j] = gen01();
sl@0
   306
    i = long_lag;
sl@0
   307
  }
sl@0
   308
sl@0
   309
  template<class It>
sl@0
   310
  void seed(It& first, It last)
sl@0
   311
  {
sl@0
   312
#ifndef BOOST_NO_STDC_NAMESPACE
sl@0
   313
    // allow for Koenig lookup
sl@0
   314
    using std::fmod;
sl@0
   315
    using std::pow;
sl@0
   316
#endif
sl@0
   317
    unsigned long mask = ~((~0u) << (w%32));   // now lowest w bits set
sl@0
   318
    RealType two32 = pow(RealType(2), 32);
sl@0
   319
    unsigned int j;
sl@0
   320
    for(j = 0; j < long_lag && first != last; ++j, ++first) {
sl@0
   321
      x[j] = RealType(0);
sl@0
   322
      for(int i = 0; i < w/32 && first != last; ++i, ++first)
sl@0
   323
        x[j] += *first / pow(two32,i+1);
sl@0
   324
      if(first != last && mask != 0)
sl@0
   325
        x[j] += fmod((*first & mask) / _modulus, RealType(1));
sl@0
   326
    }
sl@0
   327
    i = long_lag;
sl@0
   328
    if(first == last && j < long_lag)
sl@0
   329
      throw std::invalid_argument("lagged_fibonacci_01::seed");
sl@0
   330
  }
sl@0
   331
sl@0
   332
  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
sl@0
   333
  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
sl@0
   334
sl@0
   335
  result_type operator()()
sl@0
   336
  {
sl@0
   337
    if(i >= long_lag)
sl@0
   338
      fill();
sl@0
   339
    return x[i++];
sl@0
   340
  }
sl@0
   341
sl@0
   342
  static bool validation(result_type x)
sl@0
   343
  {
sl@0
   344
    result_type v = fibonacci_validation<result_type, p, q>::value();
sl@0
   345
    result_type epsilon = fibonacci_validation<result_type, p, q>::tolerance();
sl@0
   346
    // std::abs is a source of trouble: sometimes, it's not overloaded
sl@0
   347
    // for double, plus the usual namespace std noncompliance -> avoid it
sl@0
   348
    // using std::abs;
sl@0
   349
    // return abs(x - v) < 5 * epsilon
sl@0
   350
    return x > v - epsilon && x < v + epsilon;
sl@0
   351
  }
sl@0
   352
  
sl@0
   353
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
sl@0
   354
sl@0
   355
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
sl@0
   356
  template<class CharT, class Traits>
sl@0
   357
  friend std::basic_ostream<CharT,Traits>&
sl@0
   358
  operator<<(std::basic_ostream<CharT,Traits>& os, const lagged_fibonacci_01&f)
sl@0
   359
  {
sl@0
   360
#ifndef BOOST_NO_STDC_NAMESPACE
sl@0
   361
    // allow for Koenig lookup
sl@0
   362
    using std::pow;
sl@0
   363
#endif
sl@0
   364
    os << f.i << " ";
sl@0
   365
    std::ios_base::fmtflags oldflags = os.flags(os.dec | os.fixed | os.left); 
sl@0
   366
    for(unsigned int i = 0; i < f.long_lag; ++i)
sl@0
   367
      os << f.x[i] * f._modulus << " ";
sl@0
   368
    os.flags(oldflags);
sl@0
   369
    return os;
sl@0
   370
  }
sl@0
   371
sl@0
   372
  template<class CharT, class Traits>
sl@0
   373
  friend std::basic_istream<CharT, Traits>&
sl@0
   374
  operator>>(std::basic_istream<CharT, Traits>& is, lagged_fibonacci_01& f)
sl@0
   375
    {
sl@0
   376
# ifdef BOOST_RANDOM_EXTRACT_LF
sl@0
   377
        return detail::extract_lagged_fibonacci_01(is, f, f.i, f.x, f._modulus);
sl@0
   378
# else
sl@0
   379
        is >> f.i >> std::ws;
sl@0
   380
        for(unsigned int i = 0; i < f.long_lag; ++i) {
sl@0
   381
            typename lagged_fibonacci_01::result_type value;
sl@0
   382
            is >> value >> std::ws;
sl@0
   383
            f.x[i] = value / f._modulus;
sl@0
   384
        }
sl@0
   385
        return is;
sl@0
   386
# endif 
sl@0
   387
    }
sl@0
   388
#endif
sl@0
   389
sl@0
   390
  friend bool operator==(const lagged_fibonacci_01& x,
sl@0
   391
                         const lagged_fibonacci_01& y)
sl@0
   392
  { return x.i == y.i && std::equal(x.x, x.x+long_lag, y.x); }
sl@0
   393
  friend bool operator!=(const lagged_fibonacci_01& x,
sl@0
   394
                         const lagged_fibonacci_01& y)
sl@0
   395
  { return !(x == y); }
sl@0
   396
#else
sl@0
   397
  // Use a member function; Streamable concept not supported.
sl@0
   398
  bool operator==(const lagged_fibonacci_01& rhs) const
sl@0
   399
  { return i == rhs.i && std::equal(x, x+long_lag, rhs.x); }
sl@0
   400
  bool operator!=(const lagged_fibonacci_01& rhs) const
sl@0
   401
  { return !(*this == rhs); }
sl@0
   402
#endif
sl@0
   403
sl@0
   404
private:
sl@0
   405
  void fill();
sl@0
   406
  unsigned int i;
sl@0
   407
  RealType x[long_lag];
sl@0
   408
  RealType _modulus;
sl@0
   409
};
sl@0
   410
sl@0
   411
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
sl@0
   412
//  A definition is required even for integral static constants
sl@0
   413
template<class RealType, int w, unsigned int p, unsigned int q>
sl@0
   414
const bool lagged_fibonacci_01<RealType, w, p, q>::has_fixed_range;
sl@0
   415
template<class RealType, int w, unsigned int p, unsigned int q>
sl@0
   416
const unsigned int lagged_fibonacci_01<RealType, w, p, q>::long_lag;
sl@0
   417
template<class RealType, int w, unsigned int p, unsigned int q>
sl@0
   418
const unsigned int lagged_fibonacci_01<RealType, w, p, q>::short_lag;
sl@0
   419
template<class RealType, int w, unsigned int p, unsigned int q>
sl@0
   420
const int lagged_fibonacci_01<RealType,w,p,q>::word_size;
sl@0
   421
sl@0
   422
#endif
sl@0
   423
sl@0
   424
template<class RealType, int w, unsigned int p, unsigned int q>
sl@0
   425
void lagged_fibonacci_01<RealType, w, p, q>::fill()
sl@0
   426
{
sl@0
   427
  // two loops to avoid costly modulo operations
sl@0
   428
  {  // extra scope for MSVC brokenness w.r.t. for scope
sl@0
   429
  for(unsigned int j = 0; j < short_lag; ++j) {
sl@0
   430
    RealType t = x[j] + x[j+(long_lag-short_lag)];
sl@0
   431
    if(t >= RealType(1))
sl@0
   432
      t -= RealType(1);
sl@0
   433
    x[j] = t;
sl@0
   434
  }
sl@0
   435
  }
sl@0
   436
  for(unsigned int j = short_lag; j < long_lag; ++j) {
sl@0
   437
    RealType t = x[j] + x[j-short_lag];
sl@0
   438
    if(t >= RealType(1))
sl@0
   439
      t -= RealType(1);
sl@0
   440
    x[j] = t;
sl@0
   441
  }
sl@0
   442
  i = 0;
sl@0
   443
}
sl@0
   444
sl@0
   445
} // namespace random
sl@0
   446
sl@0
   447
typedef random::lagged_fibonacci_01<double, 48, 607, 273> lagged_fibonacci607;
sl@0
   448
typedef random::lagged_fibonacci_01<double, 48, 1279, 418> lagged_fibonacci1279;
sl@0
   449
typedef random::lagged_fibonacci_01<double, 48, 2281, 1252> lagged_fibonacci2281;
sl@0
   450
typedef random::lagged_fibonacci_01<double, 48, 3217, 576> lagged_fibonacci3217;
sl@0
   451
typedef random::lagged_fibonacci_01<double, 48, 4423, 2098> lagged_fibonacci4423;
sl@0
   452
typedef random::lagged_fibonacci_01<double, 48, 9689, 5502> lagged_fibonacci9689;
sl@0
   453
typedef random::lagged_fibonacci_01<double, 48, 19937, 9842> lagged_fibonacci19937;
sl@0
   454
typedef random::lagged_fibonacci_01<double, 48, 23209, 13470> lagged_fibonacci23209;
sl@0
   455
typedef random::lagged_fibonacci_01<double, 48, 44497, 21034> lagged_fibonacci44497;
sl@0
   456
sl@0
   457
sl@0
   458
// It is possible to partially specialize uniform_01<> on lagged_fibonacci_01<>
sl@0
   459
// to help the compiler generate efficient code.  For GCC, this seems useless,
sl@0
   460
// because GCC optimizes (x-0)/(1-0) to (x-0).  This is good enough for now.
sl@0
   461
sl@0
   462
} // namespace boost
sl@0
   463
sl@0
   464
#endif // BOOST_RANDOM_LAGGED_FIBONACCI_HPP