Panda3D
 All Classes Functions Variables Enumerations
mersenne.h
1 // Filename: mersenne.h
2 // Created by: darren (18Jul02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MERSENNE_H
16 #define MERSENNE_H
17 
18 /*
19  A C-program for MT19937, with initialization improved 2002/1/26.
20  Coded by Takuji Nishimura and Makoto Matsumoto.
21 
22  Before using, initialize the state by using init_genrand(seed)
23  or init_by_array(init_key, key_length).
24 
25  Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
26  All rights reserved.
27 
28  Redistribution and use in source and binary forms, with or without
29  modification, are permitted provided that the following conditions
30  are met:
31 
32  1. Redistributions of source code must retain the above copyright
33  notice, this list of conditions and the following disclaimer.
34 
35  2. Redistributions in binary form must reproduce the above copyright
36  notice, this list of conditions and the following disclaimer in the
37  documentation and/or other materials provided with the distribution.
38 
39  3. The names of its contributors may not be used to endorse or promote
40  products derived from this software without specific prior written
41  permission.
42 
43  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
47  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
48  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
50  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
51  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
52  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 
55 
56  Any feedback is very welcome.
57  http://www.math.keio.ac.jp/matumoto/emt.html
58  email: matumoto@math.keio.ac.jp
59 */
60 
61 #include "pandabase.h"
62 
63 class EXPCL_PANDA_MATHUTIL Mersenne {
64 PUBLISHED:
65  Mersenne(unsigned long seed);
66  unsigned long get_uint31();
67 
68  enum {
69  max_value = 0x7fffffff
70  };
71 
72 private:
73  enum {
74  // Period parameters
75  N = 624,
76  M = 397,
77  MATRIX_A = 0x9908b0dfUL, // constant vector a
78  UPPER_MASK = 0x80000000UL, // most significant w-r bits
79  LOWER_MASK = 0x7fffffffUL, // least significant r bits
80  };
81 
82  unsigned long mt[N]; // the array for the state vector
83  unsigned int mti; // mti==N+1 means mt[N] is not initialized
84 };
85 
86 #endif