Created by Scott Robert Ladd at Coyote Gulch Productions.
00001 //--------------------------------------------------------------------- 00002 // Algorithmic Conjurings @ http://www.coyotegulch.com 00003 // 00004 // mwc1038.cpp (libcoyotl) 00005 // 00006 // A multiply with carry psudeorandom number generator, as suggested 00007 // by George Marsaglia in Januray 2003. The original message can be 00008 // found at: 00009 // 00010 // http://forums.wolfram.com/mathgroup/archive/2003/Jan/msg00355.html 00011 // 00012 //--------------------------------------------------------------------- 00013 // 00014 // COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: 00015 // 00016 // This notice applies *only* to this specific expression of this 00017 // algorithm, and does not imply ownership or invention of the 00018 // implemented algorithm. 00019 // 00020 // If you modify this file, you may insert additional notices 00021 // immediately following this sentence. 00022 // 00023 // Copyright 2001-2004 Scott Robert Ladd. 00024 // All rights reserved, except as noted herein. 00025 // 00026 // This computer program source file is supplied "AS IS". Scott Robert 00027 // Ladd (hereinafter referred to as "Author") disclaims all warranties, 00028 // expressed or implied, including, without limitation, the warranties 00029 // of merchantability and of fitness for any purpose. The Author 00030 // assumes no liability for direct, indirect, incidental, special, 00031 // exemplary, or consequential damages, which may result from the use 00032 // of this software, even if advised of the possibility of such damage. 00033 // 00034 // The Author hereby grants anyone permission to use, copy, modify, and 00035 // distribute this source code, or portions hereof, for any purpose, 00036 // without fee, subject to the following restrictions: 00037 // 00038 // 1. The origin of this source code must not be misrepresented. 00039 // 00040 // 2. Altered versions must be plainly marked as such and must not 00041 // be misrepresented as being the original source. 00042 // 00043 // 3. This Copyright notice may not be removed or altered from any 00044 // source or altered source distribution. 00045 // 00046 // The Author specifically permits (without fee) and encourages the use 00047 // of this source code for entertainment, education, or decoration. If 00048 // you use this source code in a product, acknowledgment is not required 00049 // but would be appreciated. 00050 // 00051 // Acknowledgement: 00052 // This license is based on the wonderful simple license that 00053 // accompanies libpng. 00054 // 00055 //----------------------------------------------------------------------- 00056 // For more information on this software package, please visit 00057 // Scott's web site, Coyote Gulch Productions, at: 00058 // 00059 // http://www.coyotegulch.com 00060 //----------------------------------------------------------------------- 00061 00062 #if !defined(LIBCOYOTL_MWC1038_H) 00063 #define LIBCOYOTL_MWC1038_H 00064 00065 #include "prng.h" 00066 00067 namespace libcoyotl 00068 { 00070 00077 class mwc1038 : public prng 00078 { 00079 private: 00080 // Period parameters 00081 static const size_t N = 1038; 00082 00083 // Working storage 00084 uint32_t m_q[N]; 00085 uint32_t m_carry; 00086 int m_index; 00087 00088 public: 00090 00094 mwc1038(); 00095 00097 00101 mwc1038(uint32_t seed); 00102 00104 00108 virtual void init(uint32_t seed); 00109 00110 private: 00112 00116 void init_helper(); 00117 00118 public: 00120 00124 virtual uint32_t get_rand(); 00125 }; 00126 00127 } // end namespace libcoyotl 00128 00129 #endif
© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.