Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

mt19937rng.h

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 /* 
00024    A C-program for MT19937, with initialization improved 2002/2/10.
00025    Coded by Takuji Nishimura and Makoto Matsumoto.
00026    This is a faster version by taking Shawn Cokus's optimization,
00027    Matthe Bellew's simplification, Isaku Wada's real version.
00028 
00029    Before using, initialize the state by using init_genrand(seed) 
00030    or init_by_array(init_key, key_length).
00031 
00032    Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
00033    All rights reserved.                          
00034 
00035    Redistribution and use in source and binary forms, with or without
00036    modification, are permitted provided that the following conditions
00037    are met:
00038 
00039      1. Redistributions of source code must retain the above copyright
00040         notice, this list of conditions and the following disclaimer.
00041 
00042      2. Redistributions in binary form must reproduce the above copyright
00043         notice, this list of conditions and the following disclaimer in the
00044         documentation and/or other materials provided with the distribution.
00045 
00046      3. The names of its contributors may not be used to endorse or promote 
00047         products derived from this software without specific prior written 
00048         permission.
00049 
00050    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00051    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00052    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00053    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00054    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00055    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00056    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00057    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00058    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00059    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00060    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00061 
00062 
00063    Any feedback is very welcome.
00064    http://www.math.keio.ac.jp/matumoto/emt.html
00065    email: matumoto@math.keio.ac.jp
00066 */
00067 
00068 #ifndef SHEEP_MATH_MT19937RNG_H
00069 #define SHEEP_MATH_MT19937RNG_H
00070 
00071 #include "common/misc/config.h"
00072 
00073 #include <cassert>
00074 
00075 namespace sheep {
00076 
00077     class MT19937RNG {
00078     public:
00079         explicit MT19937RNG(unsigned long seed = 5489UL);
00080 
00081         //! Seed the generator.
00082         void Seed(unsigned long seed);
00083 
00084         //! Generates and returns a random number on [0,0xffffffff] integer interval.
00085         unsigned long RandomInt();
00086 
00087         //! Generates and returns a random number on [0,1] real interval.
00088         double RandomReal1();
00089 
00090         //! Generates and returns a random number on [0,1) real interval.
00091         double RandomReal2();
00092 
00093         //! Generates and returns a random number on [a, b] integer interval, b >= a.
00094         long RandomInt(long a, long b);
00095 
00096         //! Generates and returns a random number on [a, b] real interval, b >= a.
00097         double RandomReal1(double a, double b);
00098 
00099         //! Generates and returns a random number on [a, b) real interval, b > a.
00100         double RandomReal2(double a, double b);
00101 
00102     private:
00103         //! Period parameters.
00104         enum { N = 624, M = 397 };
00105 
00106         unsigned long state[N]; //!< The array for the state vector.
00107         int left;
00108         unsigned long *next;
00109 
00110         void next_state();
00111     };
00112 
00113 #include "mt19937rng.inl"
00114 
00115 }
00116 
00117 #endif  // !SHEEP_MATH_MT19937RNG_H

Generated on Tue May 11 01:31:51 2004 for toxic by doxygen 1.3.6