libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


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

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