beginnings of port...won't compile yet
[IRC.git] / Robust / src / Benchmarks / SingleTM / Yada / Random.java
1 public class Random {
2   long[] mt; 
3   int mti;
4   int RANDOM_DEFAULT_SEED;
5   /* period parameter */
6
7
8   public Random() {
9     RANDOM_DEFAULT_SEED = 0;
10     mt = new long[624];
11   }
12
13   public void random_alloc() {
14     init_genrand(this.RANDOM_DEFAULT_SEED);
15   }
16
17   /* initializes mt[N] with a seed */
18   public void init_genrand(int s) {
19     mt[0]= ((long)s) & 0xFFFFFFFFL;
20     for (int mti=1; mti<624; mti++) {
21       mt[mti] = (1812433253L * (mt[mti-1] ^ (mt[mti-1] >> 30)) + ((long)mti));
22       /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
23       /* In the previous versions, MSBs of the seed affect   */
24       /* only MSBs of the array mt[].                        */
25       /* 2002/01/09 modified by Makoto Matsumoto             */
26       mt[mti] &= 0xFFFFFFFFL;
27       /* for >32 bit machines */
28     }
29     this.mti=624;
30   }
31
32   public void random_seed(int seed) {
33     init_genrand(seed);
34   }
35
36   public long random_generate() {
37     long x= genrand_int32()&0xFFFFFFFFL;
38     System.out.println(x);
39     return x;
40   }
41
42   public long posrandom_generate() {
43     long r=genrand_int32();
44     if (r>0)
45       return r;
46     else 
47       return -r;
48   }
49
50   public long genrand_int32() {
51     long y;
52     int mti = this.mti;
53     long[] mt = this.mt;
54
55     if (mti >= 624) { /* generate N words at one time */
56       int kk;
57
58       if (mti == 624+1) {  /* if init_genrand() has not been called, */
59         init_genrand(5489); /* a default initial seed is used */
60         mti=this.mti;
61       }
62       for (kk=0;kk<(624-397);kk++) {
63         y = (mt[kk]&0x80000000L)|(mt[kk+1]&0x7fffffffL);
64         mt[kk] = mt[kk+397] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0L:0x9908b0dfL);
65       }
66       for (;kk<(624-1);kk++) {
67         y = (mt[kk]&0x80000000L)|(mt[kk+1]&0x7fffffffL);
68         mt[kk] = mt[kk+(397-624)] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0L:0x9908b0dfL);
69       }
70       y = (mt[624-1]&0x80000000L)|(mt[0]&0x7fffffffL);
71       mt[624-1] = mt[397-1] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0L:0x9908b0dfL);
72
73       mti = 0;
74     }
75
76     y = mt[mti++];
77
78     /* Tempering */
79     y ^= (y >> 11);
80     y ^= (y << 7) & 0x9d2c5680L;
81     y ^= (y << 15) & 0xefc60000L;
82     y ^= (y >> 18);
83
84     this.mti = mti;
85
86     return y;
87   }
88 }