libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


mwc1038.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 //
4 // mwc1038.cpp (libcoyotl)
5 //
6 // A multiply with carry psudeorandom number generator, as suggested
7 // by George Marsaglia in Januray 2003. The original message can be
8 // found at:
9 //
10 // http://forums.wolfram.com/mathgroup/archive/2003/Jan/msg00355.html
11 //
12 //---------------------------------------------------------------------
13 //
14 // COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
15 //
16 // This notice applies *only* to this specific expression of this
17 // algorithm, and does not imply ownership or invention of the
18 // implemented algorithm.
19 //
20 // If you modify this file, you may insert additional notices
21 // immediately following this sentence.
22 //
23 // Copyright 2001-2004 Scott Robert Ladd.
24 // All rights reserved, except as noted herein.
25 //
26 // This computer program source file is supplied "AS IS". Scott Robert
27 // Ladd (hereinafter referred to as "Author") disclaims all warranties,
28 // expressed or implied, including, without limitation, the warranties
29 // of merchantability and of fitness for any purpose. The Author
30 // assumes no liability for direct, indirect, incidental, special,
31 // exemplary, or consequential damages, which may result from the use
32 // of this software, even if advised of the possibility of such damage.
33 //
34 // The Author hereby grants anyone permission to use, copy, modify, and
35 // distribute this source code, or portions hereof, for any purpose,
36 // without fee, subject to the following restrictions:
37 //
38 // 1. The origin of this source code must not be misrepresented.
39 //
40 // 2. Altered versions must be plainly marked as such and must not
41 // be misrepresented as being the original source.
42 //
43 // 3. This Copyright notice may not be removed or altered from any
44 // source or altered source distribution.
45 //
46 // The Author specifically permits (without fee) and encourages the use
47 // of this source code for entertainment, education, or decoration. If
48 // you use this source code in a product, acknowledgment is not required
49 // but would be appreciated.
50 //
51 // Acknowledgement:
52 // This license is based on the wonderful simple license that
53 // accompanies libpng.
54 //
55 //-----------------------------------------------------------------------
56 // For more information on this software package, please visit
57 // Scott's web site, Coyote Gulch Productions, at:
58 //
59 // http://www.coyotegulch.com
60 //-----------------------------------------------------------------------
61 
62 #if !defined(LIBCOYOTL_MWC1038_H)
63 #define LIBCOYOTL_MWC1038_H
64 
65 #include "prng.h"
66 
67 namespace libcoyotl
68 {
70 
77  class mwc1038 : public prng
78  {
79  private:
80  // Period parameters
81  static const size_t N = 1038;
82 
83  // Working storage
84  uint32_t m_q[N];
85  uint32_t m_carry;
86  int m_index;
87 
88  public:
90 
94  mwc1038();
95 
97 
101  mwc1038(uint32_t seed);
102 
104 
108  virtual void init(uint32_t seed);
109 
110  private:
112 
116  void init_helper();
117 
118  public:
120 
124  virtual uint32_t get_rand();
125  };
126 
127 } // end namespace libcoyotl
128 
129 #endif

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