1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 A C-program for MT19937, with initialization improved 2002/1/26.
4 Coded by Takuji Nishimura and Makoto Matsumoto.
6 Before using, initialize the state by using init_genrand(seed)
7 or init_by_array(init_key, key_length).
9 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 ` notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
23 3. The names of its contributors may not be used to endorse or promote
24 products derived from this software without specific prior written
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 Any feedback is very welcome.
41 http://www.math.keio.ac.jp/matumoto/emt.html
42 email: matumoto@math.keio.ac.jp
45 /* ====================================================================
46 * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
53 * 1. Redistributions of source code must retain the above copyright
54 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in
58 * the documentation and/or other materials provided with the
61 * This work was supported in part by funding from the Defense Advanced
62 * Research Projects Agency and the National Science Foundation of the
63 * United States of America, and the CMU Sphinx Speech Consortium.
65 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
66 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
67 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
68 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
69 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
70 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
71 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
72 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
73 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
74 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
75 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77 * ====================================================================
82 * randgen.c : a portable random generator
85 * **********************************************
86 * CMU ARPA Speech Project
88 * Copyright (c) 1999 Carnegie Mellon University.
89 * ALL RIGHTS RESERVED.
90 * **********************************************
94 * Revision 1.3 2005/06/22 03:01:50 arthchan2003
97 * Revision 1.3 2005/03/30 01:22:48 archan
98 * Fixed mistakes in last updates. Add
101 * 18-Nov-04 ARCHAN (archan@cs.cmu.edu) at Carnegie Mellon University
102 * First incorporated from the Mersenne Twister Random
103 * Number Generator package. It was chosen because it is
104 * in BSD-license and its performance is quite
105 * reasonable. Of course if you look at the inventors's
106 * page. This random generator can actually gives
107 * 19937-bits period. This is already far from we need.
108 * This will possibly good enough for the next 10 years.
110 * I also downgrade the code a little bit to avoid Sphinx's
111 * developers misused it.
114 #ifndef _LIBUTIL_GENRAND_H_
115 #define _LIBUTIL_GENRAND_H_
117 #define S3_RAND_MAX_INT32 0x7fffffff
120 /* Win32/WinCE DLL gunk */
121 #include <sphinxbase/sphinxbase_export.h>
124 *\brief High performance prortable random generator created by Takuji
125 *Nishimura and Makoto Matsumoto.
127 * A high performance which applied Mersene twister primes to generate
128 * random number. If probably seeded, the random generator can achieve
129 * 19937-bits period. For technical detail. Please take a look at
130 * (FIXME! Need to search for the web site.) http://www.
141 * Macros to simplify calling of random generator function.
144 #define s3_rand_seed(s) genrand_seed(s);
145 #define s3_rand_int31() genrand_int31()
146 #define s3_rand_real() genrand_real3()
147 #define s3_rand_res53() genrand_res53()
150 *Initialize the seed of the random generator.
153 void genrand_seed(unsigned long s);
156 *generates a random number on [0,0x7fffffff]-interval
159 long genrand_int31(void);
162 *generates a random number on (0,1)-real-interval
165 double genrand_real3(void);
168 *generates a random number on [0,1) with 53-bit resolution
171 double genrand_res53(void);
177 #endif /*_LIBUTIL_GENRAND_H_*/