00001 // Filename: mersenne.h 00002 // Created by: darren (18Jul02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef MERSENNE_H 00020 #define MERSENNE_H 00021 00022 /* 00023 A C-program for MT19937, with initialization improved 2002/1/26. 00024 Coded by Takuji Nishimura and Makoto Matsumoto. 00025 00026 Before using, initialize the state by using init_genrand(seed) 00027 or init_by_array(init_key, key_length). 00028 00029 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 00030 All rights reserved. 00031 00032 Redistribution and use in source and binary forms, with or without 00033 modification, are permitted provided that the following conditions 00034 are met: 00035 00036 1. Redistributions of source code must retain the above copyright 00037 notice, this list of conditions and the following disclaimer. 00038 00039 2. Redistributions in binary form must reproduce the above copyright 00040 notice, this list of conditions and the following disclaimer in the 00041 documentation and/or other materials provided with the distribution. 00042 00043 3. The names of its contributors may not be used to endorse or promote 00044 products derived from this software without specific prior written 00045 permission. 00046 00047 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00048 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00049 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00050 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00051 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00052 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00053 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00054 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00055 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00056 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00057 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00058 00059 00060 Any feedback is very welcome. 00061 http://www.math.keio.ac.jp/matumoto/emt.html 00062 email: matumoto@math.keio.ac.jp 00063 */ 00064 00065 #include <directbase.h> 00066 00067 class EXPCL_DIRECT Mersenne { 00068 PUBLISHED: 00069 Mersenne(unsigned long seed); 00070 unsigned long get_uint31(); 00071 00072 private: 00073 enum { 00074 // Period parameters 00075 N = 624, 00076 M = 397, 00077 MATRIX_A = 0x9908b0dfUL, // constant vector a 00078 UPPER_MASK = 0x80000000UL, // most significant w-r bits 00079 LOWER_MASK = 0x7fffffffUL, // least significant r bits 00080 }; 00081 00082 unsigned long mt[N]; // the array for the state vector 00083 int mti; // mti==N+1 means mt[N] is not initialized 00084 }; 00085 00086 #endif