libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


mwc256.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 //
4 // mwc256.cpp (libcoyotl)
5 //
6 // A multiply with carry psudeorandom number generator, as suggested
7 // by George Marsaglia.
8 //---------------------------------------------------------------------
9 //
10 // Copyright 1990-2005 Scott Robert Ladd
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the
24 // Free Software Foundation, Inc.
25 // 59 Temple Place - Suite 330
26 // Boston, MA 02111-1307, USA.
27 //
28 //-----------------------------------------------------------------------
29 //
30 // For more information on this software package, please visit
31 // Scott's web site, Coyote Gulch Productions, at:
32 //
33 // http://www.coyotegulch.com
34 //
35 //-----------------------------------------------------------------------
36 
37 #if !defined(LIBCOYOTL_MWC256_H)
38 #define LIBCOYOTL_MWC256_H
39 
40 #include "prng.h"
41 
42 namespace libcoyotl
43 {
45 
49  class mwc256 : public prng
50  {
51  private:
52  // Period parameters
53  static const size_t N = 256;
54 
55  // Working storage
56  uint32_t m_q[N];
57  uint32_t m_carry;
58  uint8_t m_index;
59 
60  public:
62 
66  mwc256();
67 
69 
73  mwc256(uint32_t seed);
74 
76 
80  virtual void init(uint32_t seed);
81 
82  private:
84 
88  void init_helper();
89 
90  public:
92 
96  virtual uint32_t get_rand();
97  };
98 
99 } // end namespace libcoyotl
100 
101 #endif
virtual uint32_t get_rand()
Get the next integer.
Definition: array.h:61
Implements MWC256, a peudorandom number generator.
Definition: mwc256.h:49
An abstract definition of a peudorandom number generator.
Definition: prng.h:54
mwc256()
Default constructor, reading seed from/dev/urandom or the time.
virtual void init(uint32_t seed)
Initializes the generator with "seed".

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.