Initial import to Tizen
[profile/ivi/sphinxbase.git] / include / sphinxbase / genrand.h
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* 
3    A C-program for MT19937, with initialization improved 2002/1/26.
4    Coded by Takuji Nishimura and Makoto Matsumoto.
5
6    Before using, initialize the state by using init_genrand(seed)  
7    or init_by_array(init_key, key_length).
8
9    Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
10    All rights reserved.                          
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions
14    are met:
15
16      1. Redistributions of source code must retain the above copyright
17         notice, this list of conditions and the following disclaimer.
18
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.
22
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 
25         permission.
26
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.
38
39
40    Any feedback is very welcome.
41    http://www.math.keio.ac.jp/matumoto/emt.html
42    email: matumoto@math.keio.ac.jp
43 */
44
45 /* ====================================================================
46  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
47  * reserved.
48  *
49  * Redistribution and use in source and binary forms, with or without
50  * modification, are permitted provided that the following conditions
51  * are met:
52  *
53  * 1. Redistributions of source code must retain the above copyright
54  *    notice, this list of conditions and the following disclaimer. 
55  *
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
59  *    distribution.
60  *
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.
64  *
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.
76  *
77  * ====================================================================
78  *
79  */
80
81 /*
82  * randgen.c   : a portable random generator 
83  * 
84  *
85  * **********************************************
86  * CMU ARPA Speech Project
87  *
88  * Copyright (c) 1999 Carnegie Mellon University.
89  * ALL RIGHTS RESERVED.
90  * **********************************************
91  * 
92  * HISTORY
93  * $Log: genrand.h,v $
94  * Revision 1.3  2005/06/22 03:01:50  arthchan2003
95  * Added  keyword
96  *
97  * Revision 1.3  2005/03/30 01:22:48  archan
98  * Fixed mistakes in last updates. Add
99  *
100  * 
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. 
109  *
110  *              I also downgrade the code a little bit to avoid Sphinx's
111  *              developers misused it. 
112  */
113
114 #ifndef _LIBUTIL_GENRAND_H_
115 #define _LIBUTIL_GENRAND_H_
116
117 #define S3_RAND_MAX_INT32 0x7fffffff
118 #include <stdio.h>
119
120 /* Win32/WinCE DLL gunk */
121 #include <sphinxbase/sphinxbase_export.h>
122
123 /** \file genrand.h
124  *\brief High performance prortable random generator created by Takuji
125  *Nishimura and Makoto Matsumoto.  
126  * 
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.
131  */
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 #if 0
136 /* Fool Emacs. */
137 }
138 #endif
139
140 /**
141  * Macros to simplify calling of random generator function.
142  *
143  */
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()
148
149 /**
150  *Initialize the seed of the random generator. 
151  */
152 SPHINXBASE_EXPORT
153 void genrand_seed(unsigned long s);
154
155 /**
156  *generates a random number on [0,0x7fffffff]-interval 
157  */
158 SPHINXBASE_EXPORT
159 long genrand_int31(void);
160
161 /**
162  *generates a random number on (0,1)-real-interval 
163  */
164 SPHINXBASE_EXPORT
165 double genrand_real3(void);
166
167 /**
168  *generates a random number on [0,1) with 53-bit resolution
169  */
170 SPHINXBASE_EXPORT
171 double genrand_res53(void);
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif /*_LIBUTIL_GENRAND_H_*/
178
179
180