summaryrefslogtreecommitdiff
path: root/fuzz/prng.c
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/prng.c')
-rwxr-xr-xfuzz/prng.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/fuzz/prng.c b/fuzz/prng.c
new file mode 100755
index 0000000..fa6d4e4
--- /dev/null
+++ b/fuzz/prng.c
@@ -0,0 +1,112 @@
1/*
2 A C-program for MT19937, with initialization improved 2002/1/26.
3 Coded by Takuji Nishimura and Makoto Matsumoto.
4
5 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 1. Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18
19 3. The names of its contributors may not be used to endorse or promote
20 products derived from this software without specific prior written
21 permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35
36 Any feedback is very welcome.
37 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
38 email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
39*/
40
41#include <assert.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include "mutator_aux.h"
45
46#define init_genrand prng_init
47#define genrand_int32 prng_uint32
48
49/* Period parameters */
50#define N 624
51#define M 397
52#define MATRIX_A 0x9908b0dfUL /* constant vector a */
53#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
54#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
55
56int prng_up = 0;
57static unsigned long mt[N]; /* the array for the state vector */
58static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
59
60/* initializes mt[N] with a seed */
61void init_genrand(unsigned long s)
62{
63 mt[0]= s & 0xffffffffUL;
64 for (mti=1; mti<N; mti++) {
65 mt[mti] =
66 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
67 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
68 /* In the previous versions, MSBs of the seed affect */
69 /* only MSBs of the array mt[]. */
70 /* 2002/01/09 modified by Makoto Matsumoto */
71 mt[mti] &= 0xffffffffUL;
72 /* for >32 bit machines */
73 }
74 prng_up = 1;
75}
76
77/* generates a random number on [0,0xffffffff]-interval */
78unsigned long genrand_int32(void)
79{
80 unsigned long y;
81 static unsigned long mag01[2]={0x0UL, MATRIX_A};
82 /* mag01[x] = x * MATRIX_A for x=0,1 */
83
84 if (mti >= N) { /* generate N words at one time */
85 int kk;
86
87 assert(mti != N+1);
88
89 for (kk=0;kk<N-M;kk++) {
90 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
91 mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
92 }
93 for (;kk<N-1;kk++) {
94 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
95 mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
96 }
97 y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
98 mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
99
100 mti = 0;
101 }
102
103 y = mt[mti++];
104
105 /* Tempering */
106 y ^= (y >> 11);
107 y ^= (y << 7) & 0x9d2c5680UL;
108 y ^= (y << 15) & 0xefc60000UL;
109 y ^= (y >> 18);
110
111 return y;
112}