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