Panda3D
 All Classes Functions Variables Enumerations
mersenne.h
00001 // Filename: mersenne.h
00002 // Created by:  darren (18Jul02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MERSENNE_H
00016 #define MERSENNE_H
00017 
00018 /* 
00019    A C-program for MT19937, with initialization improved 2002/1/26.
00020    Coded by Takuji Nishimura and Makoto Matsumoto.
00021 
00022    Before using, initialize the state by using init_genrand(seed)  
00023    or init_by_array(init_key, key_length).
00024 
00025    Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
00026    All rights reserved.                          
00027 
00028    Redistribution and use in source and binary forms, with or without
00029    modification, are permitted provided that the following conditions
00030    are met:
00031 
00032      1. Redistributions of source code must retain the above copyright
00033         notice, this list of conditions and the following disclaimer.
00034 
00035      2. Redistributions in binary form must reproduce the above copyright
00036         notice, this list of conditions and the following disclaimer in the
00037         documentation and/or other materials provided with the distribution.
00038 
00039      3. The names of its contributors may not be used to endorse or promote 
00040         products derived from this software without specific prior written 
00041         permission.
00042 
00043    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00044    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00045    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00046    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00047    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00048    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00049    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00050    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00051    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00052    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00053    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00054 
00055 
00056    Any feedback is very welcome.
00057    http://www.math.keio.ac.jp/matumoto/emt.html
00058    email: matumoto@math.keio.ac.jp
00059 */
00060 
00061 #include "pandabase.h"
00062 
00063 class EXPCL_PANDA_MATHUTIL Mersenne {
00064 PUBLISHED:
00065   Mersenne(unsigned long seed);
00066   unsigned long get_uint31();
00067 
00068   enum { 
00069     max_value = 0x7fffffff
00070   };
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   unsigned int mti; // mti==N+1 means mt[N] is not initialized
00084 };
00085 
00086 #endif
 All Classes Functions Variables Enumerations