1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
5 |
< |
*/ |
6 |
< |
/** |
7 |
< |
* Misc utilities in JSR166 performance tests |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import java.util.concurrent.*; |
8 |
|
import java.util.concurrent.atomic.*; |
9 |
|
|
10 |
+ |
/** |
11 |
+ |
* Misc utilities in JSR166 performance tests |
12 |
+ |
*/ |
13 |
|
class LoopHelpers { |
14 |
|
|
15 |
|
static final SimpleRandom staticRNG = new SimpleRandom(); |
63 |
|
return x * 134775813 + 1; |
64 |
|
} |
65 |
|
|
66 |
– |
|
66 |
|
/** |
67 |
|
* Yet another random number generator |
68 |
|
*/ |
105 |
|
public static final class XorShift32Random { |
106 |
|
static final AtomicInteger seq = new AtomicInteger(8862213); |
107 |
|
int x = -1831433054; |
108 |
< |
public XorShift32Random(int seed) { x = seed; } |
108 |
> |
public XorShift32Random(int seed) { x = seed; } |
109 |
|
public XorShift32Random() { |
110 |
< |
this((int)System.nanoTime() + seq.getAndAdd(129)); |
110 |
> |
this((int) System.nanoTime() + seq.getAndAdd(129)); |
111 |
|
} |
112 |
|
public int next() { |
113 |
|
x ^= x << 6; |
117 |
|
} |
118 |
|
} |
119 |
|
|
121 |
– |
|
120 |
|
/** Multiplication-free RNG from Marsaglia "Xorshift RNGs" paper */ |
121 |
|
public static final class MarsagliaRandom { |
122 |
|
static final AtomicInteger seq = new AtomicInteger(3122688); |
126 |
|
int w = 273326509; |
127 |
|
public MarsagliaRandom(int seed) { x = seed; } |
128 |
|
public MarsagliaRandom() { |
129 |
< |
this((int)System.nanoTime() + seq.getAndAdd(129)); |
129 |
> |
this((int) System.nanoTime() + seq.getAndAdd(129)); |
130 |
|
} |
131 |
|
public int next() { |
132 |
|
int t = x ^ (x << 11); |
141 |
|
* Unsynchronized version of java.util.Random algorithm. |
142 |
|
*/ |
143 |
|
public static final class SimpleRandom { |
144 |
< |
private final static long multiplier = 0x5DEECE66DL; |
145 |
< |
private final static long addend = 0xBL; |
146 |
< |
private final static long mask = (1L << 48) - 1; |
144 |
> |
private static final long multiplier = 0x5DEECE66DL; |
145 |
> |
private static final long addend = 0xBL; |
146 |
> |
private static final long mask = (1L << 48) - 1; |
147 |
|
static final AtomicLong seq = new AtomicLong( -715159705); |
148 |
|
private long seed; |
149 |
|
|
162 |
|
public int next() { |
163 |
|
long nextseed = (seed * multiplier + addend) & mask; |
164 |
|
seed = nextseed; |
165 |
< |
return ((int)(nextseed >>> 17)) & 0x7FFFFFFF; |
165 |
> |
return ((int) (nextseed >>> 17)) & 0x7FFFFFFF; |
166 |
|
} |
167 |
|
} |
168 |
|
|