lemon/random.h
author alpar
Thu, 12 Oct 2006 10:56:26 +0000
changeset 2237 5674a5983e1e
parent 2229 4dbb6dd2dd4b
child 2242 16523135943d
permissions -rw-r--r--
Improve the configuration environment / repository layout:
- Update README
- svn-head -> svnhead version tag change (in favor of rpm build)
- rpmbuild-glpk: a script to build glpk rpm.
deba@2229
     1
/* -*- C++ -*-
deba@2229
     2
 *
deba@2229
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@2229
     4
 *
deba@2229
     5
 * Copyright (C) 2003-2006
deba@2229
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@2229
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@2229
     8
 *
deba@2229
     9
 * Permission to use, modify and distribute this software is granted
deba@2229
    10
 * provided that this copyright notice appears in all copies. For
deba@2229
    11
 * precise terms see the accompanying LICENSE file.
deba@2229
    12
 *
deba@2229
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@2229
    14
 * express or implied, and with no claim as to its suitability for any
deba@2229
    15
 * purpose.
deba@2229
    16
 *
deba@2229
    17
 */
deba@2229
    18
deba@2229
    19
#ifndef LEMON_RANDOM_H
deba@2229
    20
#define LEMON_RANDOM_H
deba@2229
    21
deba@2229
    22
#include <algorithm>
deba@2229
    23
deba@2229
    24
#include <ctime>
deba@2229
    25
#include <cmath>
deba@2229
    26
#include <cmath>
deba@2229
    27
deba@2229
    28
///\ingroup misc
deba@2229
    29
///\file
deba@2229
    30
///\brief Mersenne Twister random number generator
deba@2229
    31
///
deba@2229
    32
///\author Balazs Dezso
deba@2229
    33
deba@2229
    34
namespace lemon {
deba@2229
    35
deba@2229
    36
#if WORD_BIT == 32
deba@2229
    37
deba@2229
    38
  /// \ingroup misc
deba@2229
    39
  ///
deba@2229
    40
  /// \brief Mersenne Twister random number generator
deba@2229
    41
  ///
deba@2229
    42
  /// The Mersenne Twister is a twisted generalized feedback
deba@2229
    43
  /// shift-register generator of Matsumoto and Nishimura. The period of
deba@2229
    44
  /// this generator is \f$ 2^{19937} - 1 \f$ and it is equi-distributed in
deba@2229
    45
  /// 623 dimensions. The time performance of this generator is comparable
deba@2229
    46
  /// to the commonly used generators.
deba@2229
    47
  ///
deba@2229
    48
  /// \author Balazs Dezso
deba@2229
    49
  class Random {
deba@2229
    50
deba@2229
    51
    static const int length = 624;
deba@2229
    52
    static const int shift = 397;
deba@2229
    53
deba@2229
    54
  public:
deba@2229
    55
deba@2229
    56
    static const unsigned long min = 0ul;
deba@2229
    57
    static const unsigned long max = ~0ul;
deba@2229
    58
  
deba@2229
    59
    /// \brief Constructor
deba@2229
    60
    ///
deba@2229
    61
    /// Constructor with time dependent seeding.
deba@2229
    62
    Random() { initState(std::time(0)); }
deba@2229
    63
deba@2229
    64
    /// \brief Constructor
deba@2229
    65
    ///
deba@2229
    66
    /// Constructor
deba@2229
    67
    Random(unsigned long seed) { initState(seed); }
deba@2229
    68
deba@2229
    69
    /// \brief Copy constructor
deba@2229
    70
    ///
deba@2229
    71
    /// Copy constructor. The generated sequence will be identical to
deba@2229
    72
    /// the other sequence.
deba@2229
    73
    Random(const Random& other) { 
deba@2229
    74
      std::copy(other.state, other.state + length, state);
deba@2229
    75
      current = state + (other.current - other.state);
deba@2229
    76
    }
deba@2229
    77
deba@2229
    78
    /// \brief Assign operator
deba@2229
    79
    ///
deba@2229
    80
    /// Assign operator. The generated sequence will be identical to
deba@2229
    81
    /// the other sequence.
deba@2229
    82
    Random& operator=(const Random& other) {
deba@2229
    83
      if (&other != this) {
deba@2229
    84
        std::copy(other.state, other.state + length, state);
deba@2229
    85
        current = state + (other.current - other.state);
deba@2229
    86
      }
deba@2229
    87
      return *this;
deba@2229
    88
    }
deba@2229
    89
deba@2229
    90
    /// \brief Returns an unsigned random number
deba@2229
    91
    ///
deba@2229
    92
    /// It returns an unsigned integer random number from the range 
deba@2229
    93
    /// \f$ \{0, 1, \dots, 2^{32} - 1\} \f$.
deba@2229
    94
    unsigned long getUnsigned() {
deba@2229
    95
      if (current == state) fillState();
deba@2229
    96
      --current;
deba@2229
    97
      unsigned long rnd = *current;
deba@2229
    98
      rnd ^= (rnd >> 11);
deba@2229
    99
      rnd ^= (rnd << 7) & 0x9D2C5680ul;
deba@2229
   100
      rnd ^= (rnd << 15) & 0xEFC60000ul;
deba@2229
   101
      rnd ^= (rnd >> 18);
deba@2229
   102
      return rnd;
deba@2229
   103
    }
deba@2229
   104
deba@2229
   105
    /// \brief Returns a random number
deba@2229
   106
    ///
deba@2229
   107
    /// It returns an integer random number from the range 
deba@2229
   108
    /// \f$ \{-2^{31}, \dots, 2^{31} - 1\} \f$.
deba@2229
   109
    long getInt() {
deba@2229
   110
      return (long)getUnsigned();
deba@2229
   111
    }
deba@2229
   112
    
deba@2229
   113
    /// \brief Returns an unsigned integer random number
deba@2229
   114
    ///
deba@2229
   115
    /// It returns an unsigned integer random number from the range 
deba@2229
   116
    /// \f$ \{0, 1, \dots, 2^{31} - 1\} \f$.
deba@2229
   117
    long getNatural() {
deba@2229
   118
      return (long)(getUnsigned() >> 1);
deba@2229
   119
    }
deba@2229
   120
deba@2229
   121
    /// \brief Returns a random bool
deba@2229
   122
    ///
deba@2229
   123
    /// It returns a random bool.
deba@2229
   124
    bool getBool() {
deba@2229
   125
      return (bool)(getUnsigned() & 1);
deba@2229
   126
    }
deba@2229
   127
deba@2229
   128
    /// \brief Returns a real random number
deba@2229
   129
    ///
deba@2229
   130
    /// It returns a real random number from the range 
deba@2229
   131
    /// \f$ [0, 1) \f$. The double will have 32 significant bits.
deba@2229
   132
    double getReal() {
deba@2229
   133
      return std::ldexp((double)getUnsigned(), -32);
deba@2229
   134
    }
deba@2229
   135
deba@2229
   136
    /// \brief Returns a real random number
deba@2229
   137
    ///
deba@2229
   138
    /// It returns a real random number from the range 
deba@2229
   139
    /// \f$ [0, 1) \f$. The double will have 53 significant bits,
deba@2229
   140
    /// but it is slower than the \c getReal().
deba@2229
   141
    double getPrecReal() {
deba@2229
   142
      return std::ldexp((double)(getUnsigned() >> 5), -27) + 
deba@2229
   143
        std::ldexp((double)(getUnsigned() >> 6), -53);
deba@2229
   144
    }
deba@2229
   145
deba@2229
   146
    /// \brief Returns an unsigned random number from a given range
deba@2229
   147
    ///
deba@2229
   148
    /// It returns an unsigned integer random number from the range 
deba@2229
   149
    /// \f$ \{0, 1, \dots, n - 1\} \f$.
deba@2229
   150
    unsigned long getUnsigned(unsigned long n) {
deba@2229
   151
      unsigned long mask = n - 1, rnd;
deba@2229
   152
      mask |= mask >> 1;
deba@2229
   153
      mask |= mask >> 2;
deba@2229
   154
      mask |= mask >> 4;
deba@2229
   155
      mask |= mask >> 8;
deba@2229
   156
      mask |= mask >> 16;
deba@2229
   157
      do rnd = getUnsigned() & mask; while (rnd >= n);
deba@2229
   158
      return rnd;
deba@2229
   159
    }
deba@2229
   160
deba@2229
   161
    /// \brief Returns a random number from a given range
deba@2229
   162
    ///
deba@2229
   163
    /// It returns an unsigned integer random number from the range 
deba@2229
   164
    /// \f$ \{0, 1, \dots, n - 1\} \f$.
deba@2229
   165
    long getInt(long n) {
deba@2229
   166
      long mask = n - 1, rnd;
deba@2229
   167
      mask |= mask >> 1;
deba@2229
   168
      mask |= mask >> 2;
deba@2229
   169
      mask |= mask >> 4;
deba@2229
   170
      mask |= mask >> 8;
deba@2229
   171
      mask |= mask >> 16;
deba@2229
   172
      do rnd = getUnsigned() & mask; while (rnd >= n);
deba@2229
   173
      return rnd;
deba@2229
   174
    }
deba@2229
   175
deba@2229
   176
  private:
deba@2229
   177
deba@2229
   178
    void initState(unsigned long seed) {
deba@2229
   179
      static const unsigned long mul = 0x6c078965ul;
deba@2229
   180
deba@2229
   181
      current = state; 
deba@2229
   182
deba@2229
   183
      unsigned long *curr = state + length - 1;
deba@2229
   184
      curr[0] = seed; --curr;
deba@2229
   185
      for (int i = 1; i < length; ++i) {
deba@2229
   186
        curr[0] = (mul * ( curr[1] ^ (curr[1] >> 30) ) + i);
deba@2229
   187
        --curr;
deba@2229
   188
      }
deba@2229
   189
    }
deba@2229
   190
  
deba@2229
   191
    void fillState() {
deba@2229
   192
      static const unsigned long mask[2] = { 0x0ul, 0x9908B0DFul };
deba@2229
   193
      static const unsigned long loMask = (1ul << 31) - 1;
deba@2229
   194
      static const unsigned long hiMask = ~loMask;
deba@2229
   195
deba@2229
   196
      current = state + length; 
deba@2229
   197
deba@2229
   198
      register unsigned long *curr = state + length - 1;
deba@2229
   199
      register long num;
deba@2229
   200
      
deba@2229
   201
      num = length - shift;
deba@2229
   202
      while (num--) {
deba@2229
   203
        curr[0] = (((curr[0] & hiMask) | (curr[-1] & loMask)) >> 1) ^
deba@2229
   204
          curr[- shift] ^ mask[curr[-1] & 1ul];
deba@2229
   205
        --curr;
deba@2229
   206
      }
deba@2229
   207
      num = shift - 1;
deba@2229
   208
      while (num--) {
deba@2229
   209
        curr[0] = (((curr[0] & hiMask) | (curr[-1] & loMask)) >> 1) ^
deba@2229
   210
          curr[length - shift] ^ mask[curr[-1] & 1ul];
deba@2229
   211
        --curr;
deba@2229
   212
      }
deba@2229
   213
      curr[0] = (((curr[0] & hiMask) | (curr[length - 1] & loMask)) >> 1) ^
deba@2229
   214
        curr[length - shift] ^ mask[curr[length - 1] & 1ul];
deba@2229
   215
deba@2229
   216
    }
deba@2229
   217
  
deba@2229
   218
    unsigned long *current;
deba@2229
   219
    unsigned long state[length];
deba@2229
   220
    
deba@2229
   221
  };
deba@2229
   222
deba@2229
   223
#elif WORD_BIT == 64
deba@2229
   224
deba@2230
   225
  /// \ingroup misc
deba@2230
   226
  ///
deba@2229
   227
  /// \brief Mersenne Twister random number generator
deba@2229
   228
  ///
deba@2229
   229
  /// The Mersenne Twister is a twisted generalized feedback
deba@2229
   230
  /// shift-register generator of Matsumoto and Nishimura. The period of
deba@2229
   231
  /// this generator is \f$ 2^{19937} - 1 \f$ and it is equi-distributed in
deba@2229
   232
  /// 311 dimensions. The time performance of this generator is comparable
deba@2229
   233
  /// to the commonly used generators.
deba@2229
   234
  class Random {
deba@2229
   235
deba@2229
   236
    static const int length = 312;
deba@2229
   237
    static const int shift = 156;
deba@2229
   238
deba@2229
   239
  public:
deba@2229
   240
deba@2229
   241
    static const unsigned long min = 0ul;
deba@2229
   242
    static const unsigned long max = ~0ul;
deba@2229
   243
  
deba@2229
   244
    /// \brief Constructor
deba@2229
   245
    ///
deba@2229
   246
    /// Constructor with time dependent seeding.
deba@2229
   247
    Random() { initState(std::time(0)); }
deba@2229
   248
deba@2229
   249
    /// \brief Constructor
deba@2229
   250
    ///
deba@2229
   251
    /// Constructor
deba@2229
   252
    Random(unsigned long seed) { initState(seed); }
deba@2229
   253
deba@2229
   254
    /// \brief Copy constructor
deba@2229
   255
    ///
deba@2229
   256
    /// Copy constructor. The generated sequence will be identical to
deba@2229
   257
    /// the other sequence.
deba@2229
   258
    Random(const Random& other) { 
deba@2229
   259
      std::copy(other.state, other.state + length, state);
deba@2229
   260
      current = state + (other.current - other.state);
deba@2229
   261
    }
deba@2229
   262
deba@2229
   263
    /// \brief Assign operator
deba@2229
   264
    ///
deba@2229
   265
    /// Assign operator. The generated sequence will be identical to
deba@2229
   266
    /// the other sequence.
deba@2229
   267
    Random& operator=(const Random& other) {
deba@2229
   268
      if (&other != this) {
deba@2229
   269
        std::copy(other.state, other.state + length, state);
deba@2229
   270
        current = state + (other.current - other.state);
deba@2229
   271
      }
deba@2229
   272
      return *this;
deba@2229
   273
    }
deba@2229
   274
deba@2229
   275
    /// \brief Returns an unsigned random number
deba@2229
   276
    ///
deba@2229
   277
    /// It returns an unsigned integer random number from the range 
deba@2229
   278
    /// \f$ \{0, 1, \dots, 2^{64} - 1\} \f$.
deba@2229
   279
    unsigned long getUnsigned() {
deba@2229
   280
      if (current == state) fillState();
deba@2229
   281
      --current;
deba@2229
   282
      unsigned long rnd = *current;
deba@2229
   283
      rnd ^= (rnd >> 29) & 0x5555555555555555ul;
deba@2229
   284
      rnd ^= (rnd << 17) & 0x71D67FFFEDA60000ul;
deba@2229
   285
      rnd ^= (rnd << 37) & 0xFFF7EEE000000000ul;
deba@2229
   286
      rnd ^= (rnd >> 43);
deba@2229
   287
      return rnd;
deba@2229
   288
    }
deba@2229
   289
deba@2229
   290
    /// \brief Returns a random number
deba@2229
   291
    ///
deba@2229
   292
    /// It returns an integer random number from the range 
deba@2229
   293
    /// \f$ \{-2^{63}, \dots, 2^{63} - 1\} \f$.
deba@2229
   294
    long getInt() {
deba@2229
   295
      return (long)getUnsigned();
deba@2229
   296
    }
deba@2229
   297
    
deba@2229
   298
    /// \brief Returns an unsigned integer random number
deba@2229
   299
    ///
deba@2229
   300
    /// It returns an unsigned integer random number from the range 
deba@2229
   301
    /// \f$ \{0, 1, \dots, 2^{63} - 1\} \f$.
deba@2229
   302
    long getNatural() {
deba@2229
   303
      return (long)(getUnsigned() >> 1);
deba@2229
   304
    }
deba@2229
   305
deba@2229
   306
    /// \brief Returns a random bool
deba@2229
   307
    ///
deba@2229
   308
    /// It returns a random bool.
deba@2229
   309
    bool getBool() {
deba@2229
   310
      return (bool)(getUnsigned() & 1);
deba@2229
   311
    }
deba@2229
   312
deba@2229
   313
    /// \brief Returns a real random number
deba@2229
   314
    ///
deba@2229
   315
    /// It returns a real random number from the range 
deba@2229
   316
    /// \f$ [0, 1) \f$.
deba@2229
   317
    double getReal() {
deba@2229
   318
      return std::ldexp((double)(getUnsigned() >> 11), -53);
deba@2229
   319
    }
deba@2229
   320
deba@2229
   321
    /// \brief Returns a real random number
deba@2229
   322
    ///
deba@2229
   323
    /// It returns a real random number from the range 
deba@2229
   324
    /// \f$ [0, 1) \f$. This function is identical to the \c getReal().
deba@2229
   325
    double getPrecReal() {
deba@2229
   326
      return getReal();
deba@2229
   327
    }
deba@2229
   328
deba@2229
   329
    /// \brief Returns an unsigned random number from a given range
deba@2229
   330
    ///
deba@2229
   331
    /// It returns an unsigned integer random number from the range 
deba@2229
   332
    /// \f$ \{0, 1, \dots, n - 1\} \f$.
deba@2229
   333
    unsigned long getUnsigned(unsigned long n) {
deba@2229
   334
      unsigned long mask = n - 1, rnd;
deba@2229
   335
      mask |= mask >> 1;
deba@2229
   336
      mask |= mask >> 2;
deba@2229
   337
      mask |= mask >> 4;
deba@2229
   338
      mask |= mask >> 8;
deba@2229
   339
      mask |= mask >> 16;
deba@2229
   340
      mask |= mask >> 32;
deba@2229
   341
      do rnd = getUnsigned() & mask; while (rnd >= n);
deba@2229
   342
      return rnd;
deba@2229
   343
    }
deba@2229
   344
deba@2229
   345
    /// \brief Returns a random number from a given range
deba@2229
   346
    ///
deba@2229
   347
    /// It returns an unsigned integer random number from the range 
deba@2229
   348
    /// \f$ \{0, 1, \dots, n - 1\} \f$.
deba@2229
   349
    long getInt(long n) {
deba@2229
   350
      long mask = n - 1, rnd;
deba@2229
   351
      mask |= mask >> 1;
deba@2229
   352
      mask |= mask >> 2;
deba@2229
   353
      mask |= mask >> 4;
deba@2229
   354
      mask |= mask >> 8;
deba@2229
   355
      mask |= mask >> 16;
deba@2229
   356
      mask |= mask >> 32;
deba@2229
   357
      do rnd = getUnsigned() & mask; while (rnd >= n);
deba@2229
   358
      return rnd;
deba@2229
   359
    }
deba@2229
   360
deba@2229
   361
  private:
deba@2229
   362
deba@2229
   363
    void initState(unsigned long seed) {
deba@2229
   364
deba@2229
   365
      static const unsigned long mul = 0x5851F42D4C957F2Dul;
deba@2229
   366
deba@2229
   367
      current = state; 
deba@2229
   368
deba@2229
   369
      unsigned long *curr = state + length - 1;
deba@2229
   370
      curr[0] = seed; --curr;
deba@2229
   371
      for (int i = 1; i < length; ++i) {
deba@2229
   372
        curr[0] = (mul * ( curr[1] ^ (curr[1] >> 62) ) + i);
deba@2229
   373
        --curr;
deba@2229
   374
      }
deba@2229
   375
    }
deba@2229
   376
  
deba@2229
   377
    void fillState() {
deba@2229
   378
      static const unsigned long mask[2] = { 0x0ul, 0xB5026F5AA96619E9ul };
deba@2229
   379
      static const unsigned long loMask = (1ul << 31) - 1;
deba@2229
   380
      static const unsigned long hiMask = ~loMask;
deba@2229
   381
deba@2229
   382
      current = state + length; 
deba@2229
   383
deba@2229
   384
      register unsigned long *curr = state + length - 1;
deba@2229
   385
      register int num;
deba@2229
   386
      
deba@2229
   387
      num = length - shift;
deba@2229
   388
      while (num--) {
deba@2229
   389
        curr[0] = (((curr[0] & hiMask) | (curr[-1] & loMask)) >> 1) ^
deba@2229
   390
          curr[- shift] ^ mask[curr[-1] & 1ul];
deba@2229
   391
        --curr;
deba@2229
   392
      }
deba@2229
   393
      num = shift - 1;
deba@2229
   394
      while (num--) {
deba@2229
   395
        curr[0] = (((curr[0] & hiMask) | (curr[-1] & loMask)) >> 1) ^
deba@2229
   396
          curr[length - shift] ^ mask[curr[-1] & 1ul];
deba@2229
   397
        --curr;
deba@2229
   398
      }
deba@2229
   399
      curr[0] = (((curr[0] & hiMask) | (curr[length - 1] & loMask)) >> 1) ^
deba@2229
   400
        curr[length - shift] ^ mask[curr[length - 1] & 1ul];
deba@2229
   401
deba@2229
   402
    }
deba@2229
   403
  
deba@2229
   404
    unsigned long *current;
deba@2229
   405
    unsigned long state[length];
deba@2229
   406
    
deba@2229
   407
  };
deba@2229
   408
deba@2229
   409
#else
deba@2229
   410
deba@2230
   411
  /// \ingroup misc
deba@2230
   412
  ///
deba@2229
   413
  /// \brief Mersenne Twister random number generator
deba@2229
   414
  ///
deba@2229
   415
  /// The Mersenne Twister is a twisted generalized feedback
deba@2229
   416
  /// shift-register generator of Matsumoto and Nishimura. There is
deba@2229
   417
  /// two different implementation in the Lemon library, one for
deba@2229
   418
  /// 32-bit processors and one for 64-bit processors. The period of
deba@2229
   419
  /// the generated sequence is \f$ 2^{19937} - 1 \f$, the generated
deba@2229
   420
  /// sequence of 32-bit random numbers is equi-distributed in 623
deba@2229
   421
  /// dimensions. The time performance of this generator is comparable
deba@2229
   422
  /// to the commonly used generators.
deba@2229
   423
  class Random {
deba@2229
   424
  public:
deba@2229
   425
deba@2229
   426
    static const unsigned long min = 0ul;
deba@2229
   427
    static const unsigned long max = ~0ul;
deba@2229
   428
  
deba@2229
   429
    /// \brief Constructor
deba@2229
   430
    ///
deba@2229
   431
    /// Constructor with time dependent seeding.
deba@2229
   432
    Random() {}
deba@2229
   433
deba@2229
   434
    /// \brief Constructor
deba@2229
   435
    ///
deba@2229
   436
    /// Constructor
deba@2229
   437
    Random(unsigned long seed) {}
deba@2229
   438
deba@2229
   439
    /// \brief Copy constructor
deba@2229
   440
    ///
deba@2229
   441
    /// Copy constructor. The generated sequence will be identical to
deba@2229
   442
    /// the other sequence.
deba@2229
   443
    Random(const Random& other) {}
deba@2229
   444
deba@2229
   445
    /// \brief Assign operator
deba@2229
   446
    ///
deba@2229
   447
    /// Assign operator. The generated sequence will be identical to
deba@2229
   448
    /// the other sequence.
deba@2229
   449
    Random& operator=(const Random& other) { return *this; }
deba@2229
   450
deba@2229
   451
    /// \brief Returns an unsigned random number
deba@2229
   452
    ///
deba@2229
   453
    /// It returns an unsigned integer random number from the range 
deba@2229
   454
    /// \f$ \{0, 1, \dots, 2^{64} - 1\} \f$ for 64-bit processors and from
deba@2229
   455
    /// \f$ \{0, 1, \dots, 2^{32} - 1\} \f$ for 32-bit processors.
deba@2229
   456
    unsigned long getUnsigned() { return 0ul; }
deba@2229
   457
deba@2229
   458
    /// \brief Returns a random number
deba@2229
   459
    ///
deba@2229
   460
    /// It returns an integer random number from the range 
deba@2229
   461
    /// \f$ \{-2^{63}, \dots, 2^{63} - 1\} \f$ for 64-bit processors and from
deba@2229
   462
    /// \f$ \{-2^{31}, \dots, 2^{31} - 1\} \f$ for 32-bit processors.
deba@2229
   463
    long getInt() { return 0l; }
deba@2229
   464
    
deba@2229
   465
    /// \brief Returns an unsigned integer random number
deba@2229
   466
    ///
deba@2229
   467
    /// It returns an unsigned integer random number from the range 
deba@2229
   468
    /// \f$ \{0, 1, \dots, 2^{63} - 1\} \f$ for 64-bit processors and
deba@2229
   469
    /// from \f$ \{0, 1, \dots, 2^{31} - 1\} \f$ for 32-bit processors.
deba@2229
   470
    long getNatural() { return 0l; }
deba@2229
   471
deba@2229
   472
    /// \brief Returns a random bool
deba@2229
   473
    ///
deba@2229
   474
    /// It returns a random bool.
deba@2229
   475
    bool getBool() { return false; }
deba@2229
   476
deba@2229
   477
    /// \brief Returns a real random number
deba@2229
   478
    ///
deba@2229
   479
    /// It returns a real random number from the range 
deba@2229
   480
    /// \f$ [0, 1) \f$. For 32-bit processors the generated random
deba@2229
   481
    /// number will just have 32 significant bits.
deba@2229
   482
    double getReal() { return 0.0; }
deba@2229
   483
deba@2229
   484
    /// \brief Returns a real random number
deba@2229
   485
    ///
deba@2229
   486
    /// It returns a real random number from the range 
deba@2229
   487
    /// \f$ [0, 1) \f$. This function returns random numbers with 53
deba@2229
   488
    /// significant bits for 32-bit processors. For 64-bit processors
deba@2229
   489
    /// it is identical to the \c getReal().
deba@2229
   490
    double getPrecReal() { return 0.0; }
deba@2229
   491
deba@2229
   492
    /// \brief Returns an unsigned random number from a given range
deba@2229
   493
    ///
deba@2229
   494
    /// It returns an unsigned integer random number from the range 
deba@2229
   495
    /// \f$ \{0, 1, \dots, n - 1\} \f$.
deba@2229
   496
    unsigned long getUnsigned(unsigned long n) { return 0; }
deba@2229
   497
deba@2229
   498
    /// \brief Returns a random number from a given range
deba@2229
   499
    ///
deba@2229
   500
    /// It returns an unsigned integer random number from the range 
deba@2229
   501
    /// \f$ \{0, 1, \dots, n - 1\} \f$.
deba@2229
   502
    long getInt(long n) { return 0; }
deba@2229
   503
deba@2229
   504
  };
deba@2229
   505
deba@2229
   506
#endif
deba@2229
   507
deba@2229
   508
  /// \brief Global random number generator instance
deba@2229
   509
  ///
deba@2229
   510
  /// A global mersenne twister random number generator instance
deba@2229
   511
  extern Random rnd;
deba@2229
   512
deba@2229
   513
}
deba@2229
   514
deba@2229
   515
#endif