5742
|
1 /* |
|
2 A C-program for MT19937, with initialization improved 2002/2/10. |
|
3 Coded by Takuji Nishimura and Makoto Matsumoto. |
|
4 This is a faster version by taking Shawn Cokus's optimization, |
|
5 Matthe Bellew's simplification, Isaku Wada's real version. |
|
6 David Bateman added normal and exponential distributions following |
|
7 Marsaglia and Tang's Ziggurat algorithm. |
|
8 |
|
9 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, |
|
10 Copyright (C) 2004, David Bateman |
|
11 All rights reserved. |
|
12 |
|
13 Redistribution and use in source and binary forms, with or without |
|
14 modification, are permitted provided that the following conditions |
|
15 are met: |
|
16 |
|
17 1. Redistributions of source code must retain the above copyright |
|
18 notice, this list of conditions and the following disclaimer. |
|
19 |
|
20 2. Redistributions in binary form must reproduce the above copyright |
|
21 notice, this list of conditions and the following disclaimer in the |
|
22 documentation and/or other materials provided with the distribution. |
|
23 |
|
24 3. The names of its contributors may not be used to endorse or promote |
|
25 products derived from this software without specific prior written |
|
26 permission. |
|
27 |
|
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
|
32 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
33 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
34 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
35 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
36 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
37 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
38 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
39 |
|
40 */ |
|
41 |
|
42 #ifndef _RANDMTZIG_H |
|
43 #define _RANDMTZIG_H |
|
44 |
|
45 #ifdef HAVE_CONFIG_H |
|
46 #include <config.h> |
|
47 #endif |
|
48 |
|
49 #include "oct-types.h" |
|
50 |
|
51 #define MT_N 624 |
|
52 |
|
53 #ifdef __cplusplus |
|
54 extern "C" { |
|
55 #endif |
|
56 |
|
57 #ifdef HAVE_INTTYPES_H |
|
58 #include <inttypes.h> |
|
59 #else |
|
60 #if SIZEOF_INT == 4 |
|
61 typedef unsigned int uint32_t; |
|
62 #elif SIZEOF_LONG == 4 |
|
63 typedef unsigned long uint32_t; |
|
64 #else |
|
65 #error "No 4 byte integer type found!" |
|
66 #endif |
|
67 |
|
68 #if SIZEOF_LONG == 8 |
|
69 typedef unsigned long uint64_t; |
|
70 #else |
|
71 #if SIZEOF_LONG_LONG == 8 |
|
72 typedef unsigned long long uint64_t; |
|
73 #endif |
|
74 #endif |
|
75 #endif |
|
76 |
|
77 /* === Mersenne Twister === */ |
|
78 extern void oct_init_by_int (uint32_t s); |
|
79 extern void oct_init_by_array (uint32_t init_key[], int key_length); |
|
80 extern void oct_init_by_entropy (void); |
|
81 extern void oct_set_state (uint32_t save[]); |
|
82 extern void oct_get_state (uint32_t save[]); |
|
83 |
|
84 /* === Array generators === */ |
|
85 extern double oct_randu (void); |
|
86 extern double oct_randn (void); |
|
87 extern double oct_rande (void); |
|
88 |
|
89 /* === Array generators === */ |
|
90 extern void oct_fill_randu (octave_idx_type n, double *p); |
|
91 extern void oct_fill_randn (octave_idx_type n, double *p); |
|
92 extern void oct_fill_rande (octave_idx_type n, double *p); |
|
93 |
|
94 #ifdef __cplusplus |
|
95 } |
|
96 #endif |
|
97 #endif |
|
98 |
|
99 /* |
|
100 ;;; Local Variables: *** |
|
101 ;;; mode: C *** |
|
102 ;;; End: *** |
|
103 */ |
|
104 |