Ported over bamboo benchmarks for use as non-Bamboo java benchmarks.
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / NON_BAMBOO / JGFMonteCarlo / MyRandom.java
1 public class MyRandom {
2
3     public int iseed;
4     public float v1,v2;
5
6     public MyRandom(int iseed, float v1, float v2) {
7         this.iseed = iseed;
8         this.v1 = v1;
9         this.v2 = v2;
10     }
11
12     public float update() {
13         float rand;
14         float scale= (float)4.656612875e-10;
15
16         int is1,is2,iss2;
17         int imult= 16807;
18         int imod = 2147483647;
19         int seed = this.iseed;
20
21         if (seed<=0) { 
22             iseed = seed = 1; 
23         }
24
25         is2 = seed % 32768;
26         is1 = seed / 32768;
27         iss2 = is2 * imult;
28         is2 = iss2 % 32768;
29         is1 = (is1 * imult + iss2 / 32768) % (65536);
30
31         iseed = seed = (is1 * 32768 + is2) % imod;
32
33         rand = scale * seed;
34
35         return rand;
36
37     }
38
39     public float seed() {
40
41         float s,u1,u2,r;
42         s = (float)1.0;
43         //do {
44             u1 = update();
45             u2 = update();
46
47             v1 = (float)2.0 * u1 - (float)1.0;
48             v2 = (float)2.0 * u2 - (float)1.0;
49             s = v1*v1 + v2*v2;
50         //} while (s >= (float)1.0);
51          s = s - (int)s;
52         //System.printI(0xb4);
53         r = Math.sqrtf((float)(-2.0*Math.logf(s))/(float)s);
54         //System.printI(0xb5);
55         return r;
56
57     }
58 }