12 |
|
// Some mindless computation to do between synchronizations... |
13 |
|
|
14 |
|
/** |
15 |
< |
* generates 32 bit pseudo-random numbers. |
15 |
> |
* generates 32 bit pseudo-random numbers. |
16 |
|
* Adapted from http://www.snippets.org |
17 |
|
*/ |
18 |
< |
public static int compute1(int x) { |
18 |
> |
public static int compute1(int x) { |
19 |
|
int lo = 16807 * (x & 0xFFFF); |
20 |
|
int hi = 16807 * (x >>> 16); |
21 |
|
lo += (hi & 0x7FFF) << 16; |
35 |
|
* Computes a linear congruential random number a random number |
36 |
|
* of times. |
37 |
|
*/ |
38 |
< |
public static int compute2(int x) { |
38 |
> |
public static int compute2(int x) { |
39 |
|
int loops = (x >>> 4) & 7; |
40 |
|
while (loops-- > 0) { |
41 |
|
x = (x * 2147483647) % 16807; |
43 |
|
return x; |
44 |
|
} |
45 |
|
|
46 |
< |
public static int compute3(int x) { |
46 |
> |
/** |
47 |
> |
* Yet another random number generator |
48 |
> |
*/ |
49 |
> |
public static int compute3(int x) { |
50 |
|
int t = (x % 127773) * 16807 - (x / 127773) * 2836; |
51 |
|
return (t > 0)? t : t + 0x7fffffff; |
52 |
|
} |
53 |
|
|
54 |
|
/** |
55 |
+ |
* Yet another random number generator |
56 |
+ |
*/ |
57 |
+ |
public static int compute4(int x) { |
58 |
+ |
return x * 134775813 + 1; |
59 |
+ |
} |
60 |
+ |
|
61 |
+ |
/** |
62 |
|
* An actually useful random number generator, but unsynchronized. |
63 |
|
* Basically same as java.util.Random. |
64 |
|
*/ |
109 |
|
b.replace(b.length()-num.length(), b.length(), num); |
110 |
|
return b.toString(); |
111 |
|
} |
112 |
< |
|
112 |
> |
|
113 |
|
} |