![]() |
rtVTK
0.6.0
|
00001 00002 /* genrand() generates one pseudorandom unsigned integer (32bit) */ 00003 /* which is uniformly distributed among 0 to 2^32-1 for each */ 00004 /* call. seed(seed) set initial values to the working area */ 00005 /* of 624 words. Before genrand(), seed(seed) must be */ 00006 /* called once. (seed is any 32-bit integer except for 0). */ 00007 /* Coded by Takuji Nishimura, considering the suggestions by */ 00008 /* Topher Cooper and Marc Rieffel in July-Aug. 1997. */ 00009 00010 /* This library is free software; you can redistribute it and/or */ 00011 /* modify it under the terms of the GNU Library General Public */ 00012 /* License as published by the Free Software Foundation; either */ 00013 /* version 2 of the License, or (at your option) any later */ 00014 /* version. */ 00015 00016 /* This library is distributed in the hope that it will be useful, */ 00017 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00018 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ 00019 /* See the GNU Library General Public License for more details. */ 00020 /* You should have received a copy of the GNU Library General */ 00021 /* Public License along with this library; if not, write to the */ 00022 /* Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */ 00023 /* 02111-1307 USA */ 00024 00025 /* Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. */ 00026 /* Any feedback is very welcome. For any question, comments, */ 00027 /* see http://www.math.keio.ac.jp/matumoto/emt.html or email */ 00028 /* matumoto@math.keio.ac.jp */ 00029 00030 /* A C++-program for MT19937 */ 00031 /* Adapted to c++ by James Bigler */ 00032 00033 /****************************************************************************** 00034 * Adapted for use with rtVTK 00035 * Christiaan Gribble 00036 * 8 August 2012 00037 * 00038 * Copyright (c) 2012, Grove City College 00039 * All rights reserved. 00040 * 00041 * Redistribution and use in source and binary forms, with or without 00042 * modification, are permitted provided that the following conditions are 00043 * met: 00044 * 00045 * * Redistributions of source code must retain the above copyright 00046 * notice, this list of conditions and the following disclaimer. 00047 * 00048 * * Redistributions in binary form must reproduce the above copyright 00049 * notice, this list of conditions and the following disclaimer in 00050 * the documentation and/or other materials provided with the 00051 * distribution. 00052 * 00053 * * Neither the name of Grove City College nor the names of its 00054 * contributors may be used to endorse or promote products derived 00055 * from this software without specific prior written permission. 00056 * 00057 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00058 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00059 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00060 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00061 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00062 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00063 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00064 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00065 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00066 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00067 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00068 * 00069 */ 00070 00071 00072 #ifndef Math_mtRNG_h 00073 #define Math_mtRNG_h 00074 00075 #include <Core/Types.h> 00076 00078 // Mersenne Twister period parameters 00079 00080 #define MT_RNG_N 624 00081 #define MT_RNG_M 397 00082 00083 namespace MathF 00084 { 00085 00087 // Class definition 00088 00093 class mtRNG 00094 { 00095 public: 00096 static const float scale; 00097 00098 mtRNG(ulong = 1234); 00099 00100 void seed(ulong); 00101 float value() const; 00102 00103 private: 00104 00105 mutable ulong mt[MT_RNG_N]; 00106 mutable int mti; 00107 }; 00108 00109 inline mtRNG::mtRNG(ulong seed_) 00110 { 00111 seed(seed_); 00112 } 00113 00114 } // namespace MathF 00115 00116 #endif // Math_mtRNG_h