4 int RANDOM_DEFAULT_SEED;
9 RANDOM_DEFAULT_SEED = 0;
13 public void random_alloc() {
14 init_genrand(this.RANDOM_DEFAULT_SEED);
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 */
32 public void random_seed(int seed) {
36 public long random_generate() {
37 long x= genrand_int32()&0xFFFFFFFFL;
41 public long posrandom_generate() {
42 long r=genrand_int32();
49 public long genrand_int32() {
54 if (mti >= 624) { /* generate N words at one time */
57 if (mti == 624+1) { /* if init_genrand() has not been called, */
58 init_genrand(5489); /* a default initial seed is used */
61 for (kk=0;kk<(624-397);kk++) {
62 y = (mt[kk]&0x80000000L)|(mt[kk+1]&0x7fffffffL);
63 mt[kk] = mt[kk+397] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0L:0x9908b0dfL);
65 for (;kk<(624-1);kk++) {
66 y = (mt[kk]&0x80000000L)|(mt[kk+1]&0x7fffffffL);
67 mt[kk] = mt[kk+(397-624)] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0L:0x9908b0dfL);
69 y = (mt[624-1]&0x80000000L)|(mt[0]&0x7fffffffL);
70 mt[624-1] = mt[397-1] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0L:0x9908b0dfL);
79 y ^= (y << 7) & 0x9d2c5680L;
80 y ^= (y << 15) & 0xefc60000L;