Imported Upstream version 1.41.0
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-random / src / mt19937ar.h
1 /*
2 ** mt19937ar.h - MT Random functions
3 **
4 ** Copyright (C) 1997 - 2016, Makoto Matsumoto and Takuji Nishimura,
5 ** All rights reserved.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining
8 ** a copy of this software and associated documentation files (the
9 ** "Software"), to deal in the Software without restriction, including
10 ** without limitation the rights to use, copy, modify, merge, publish,
11 ** distribute, sublicense, and/or sell copies of the Software, and to
12 ** permit persons to whom the Software is furnished to do so, subject to
13 ** the following conditions:
14 **
15 ** The above copyright notice and this permission notice shall be
16 ** included in all copies or substantial portions of the Software.
17 **
18 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **
26 ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
27 **
28 ** Any feedback is very welcome.
29 ** http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
30 ** email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
31 **
32 ** This version is modified by mruby developers. If you see any problem,
33 ** contact us first at https://github.com/mruby/mruby/issues
34 */
35
36 #define N 624
37
38 typedef struct {
39   unsigned long mt[N];
40   int mti;
41   union {
42     unsigned long int_;
43     double double_;
44   } gen;
45
46   mrb_int seed;
47   mrb_bool has_seed : 1;
48 } mt_state;
49
50 void mrb_random_init_genrand(mt_state *, unsigned long);
51 unsigned long mrb_random_genrand_int32(mt_state *);
52 double mrb_random_genrand_real1(mt_state *t);
53
54 /* initializes mt[N] with a seed */
55 void init_genrand(unsigned long s);
56
57 /* initialize by an array with array-length */
58 /* init_key is the array for initializing keys */
59 /* key_length is its length */
60 /* slight change for C++, 2004/2/26 */
61 void init_by_array(unsigned long init_key[], int key_length);
62
63 /* generates a random number on [0,0xffffffff]-interval */
64 unsigned long genrand_int32(void);
65
66 /* generates a random number on [0,0x7fffffff]-interval */
67 long genrand_int31(void);
68
69 /* These real versions are due to Isaku Wada, 2002/01/09 added */
70 /* generates a random number on [0,1]-real-interval */
71 double genrand_real1(void);
72
73 /* generates a random number on [0,1)-real-interval */
74 double genrand_real2(void);
75
76 /* generates a random number on (0,1)-real-interval */
77 double genrand_real3(void);
78
79 /* generates a random number on [0,1) with 53-bit resolution*/
80 double genrand_res53(void);