Debian Codegraph @

libutil/mt19937ar/tt800.c

raw
1 /* http://random.mat.sbg.ac.at/ftp/pub/data/tt800.c */
2
3 /* A C-program for TT800 : July 8th 1996 Version */
4 /* by M. Matsumoto, email: [email protected] */
5 /* genrand() generate one pseudorandom number with double precision */
6 /* which is uniformly distributed on [0,1]-interval */
7 /* for each call. One may choose any initial 25 seeds */
8 /* except all zeros. */
9
10 /* See: ACM Transactions on Modelling and Computer Simulation, */
11 /* Vol. 4, No. 3, 1994, pages 254-266. */
12
13 #include <stdio.h>
14 #define N 25
15 #define M 7
16
17 double
18 genrand()
19 {
20 unsigned long y;
21 static int k = 0;
22 static unsigned long x[N]={ /* initial 25 seeds, change as you wish */
23 0x95f24dab, 0x0b685215, 0xe76ccae7, 0xaf3ec239, 0x715fad23,
24 0x24a590ad, 0x69e4b5ef, 0xbf456141, 0x96bc1b7b, 0xa7bdf825,
25 0xc1de75b7, 0x8858a9c9, 0x2da87693, 0xb657f9dd, 0xffdc8a9f,
26 0x8121da71, 0x8b823ecb, 0x885d05f5, 0x4e20cd47, 0x5a9ad5d9,
27 0x512c0c03, 0xea857ccd, 0x4cc1d30f, 0x8891a8a1, 0xa6b7aadb
28 };
29 static unsigned long mag01[2]={
30 0x0, 0x8ebfd028 /* this is magic vector `a', don't change */
31 };
32 if (k==N) { /* generate N words at one time */
33 int kk;
34 for (kk=0;kk<N-M;kk++) {
35 x[kk] = x[kk+M] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2];
36 }
37 for (; kk<N;kk++) {
38 x[kk] = x[kk+(M-N)] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2];
39 }
40 k=0;
41 }
42 y = x[k];
43 y ^= (y << 7) & 0x2b5b2500; /* s and b, magic vectors */
44 y ^= (y << 15) & 0xdb8b0000; /* t and c, magic vectors */
45 y &= 0xffffffff; /* you may delete this line if word size = 32 */
46 /*
47 the following line was added by Makoto Matsumoto in the 1996 version
48 to improve lower bit's corellation.
49 Delete this line to o use the code published in 1994.
50 */
51 y ^= (y >> 16); /* added to the 1994 version */
52 k++;
53 return( (double) y / (unsigned long) 0xffffffff);
54 }
55
56 /* this main() output first 50 generated numbers */
57 main()
58 { int j;
59 for (j=0; j<100000; j++) {
60 printf("%5f ", genrand());
61 if (j%8==7) printf("\n");
62 }
63 printf("\n");
64 }