2 //////////////////////////////////////////////////////////////////////////////
3 // This file includes code derived from the original Mersenne Twister Code
4 // by Makoto Matsumoto and Takuji Nishimura
5 // and is subject to their original copyright notice copied below:
6 //////////////////////////////////////////////////////////////////////////////
8 //////////////////////////////////////////////////////////////////////////////
9 // COPYRIGHT NOTICE FOR MERSENNE TWISTER CODE
11 // Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
12 // All rights reserved.
14 // Redistribution and use in source and binary forms, with or without
15 // modification, are permitted provided that the following conditions
18 // 1. Redistributions of source code must retain the above copyright
19 // notice, this list of conditions and the following disclaimer.
21 // 2. Redistributions in binary form must reproduce the above copyright
22 // notice, this list of conditions and the following disclaimer in the
23 // documentation and/or other materials provided with the distribution.
25 // 3. The names of its contributors may not be used to endorse or promote
26 // products derived from this software without specific prior written
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
33 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ///////////////////////////////////////////////////////////////////////////////
47 // Define a quick and dirty generator
48 #define RANDMUL 1664525L
49 #define RANDADD 1013904223L
51 #define RAND(seed) ((seed = seed * RANDMUL + RANDADD) & 0xFFFFFFFF)
54 // Implements the Mersenne Twister as default random number generator.
55 // Compilation flag __NO_MERSENNE sets default generator to
56 // a minimal Park-Miller with Bays-Durham shuffle and added safe guards.
59 // values for "minimal random values"
64 // and for normal deviates
70 // Array for Mersenne state vector
73 // Used to signal that Mersenne state vector is not initialized
79 Random(long s = 0x7654321);
82 // Next bit in series of 0s and 1s
83 int Binary(); // Next bit in series of 0s and 1s
85 // Next value in series, between 0 and 1
89 unsigned long NextInt();
91 // Random number form N(0,1)
95 void InitMersenne(unsigned long s);
97 // Random number between 0 and 1
101 // Random number between arbitrary bounds
102 double Uniform(double lo = 0.0, double hi = 1.0)
104 return lo + (hi - lo) * Next();
107 void Choose(int * array, int n, int k);
108 void Choose(int * array, float * weights, int n, int k);
112 extern Random globalRandom;