71 |
|
return 36969 * (x & 65535) + (x >> 16); |
72 |
|
} |
73 |
|
|
74 |
+ |
/** |
75 |
+ |
* Marsaglia xorshift (1, 3, 10) |
76 |
+ |
*/ |
77 |
+ |
public static int compute6(int y) { |
78 |
+ |
y ^= y << 1; |
79 |
+ |
y ^= y >>> 3; |
80 |
+ |
y ^= (y << 10); |
81 |
+ |
return y; |
82 |
+ |
} |
83 |
+ |
|
84 |
+ |
/** |
85 |
+ |
* Marsaglia xorshift (6, 21, 7) |
86 |
+ |
*/ |
87 |
+ |
public static int compute7(int y) { |
88 |
+ |
y ^= y << 6; |
89 |
+ |
y ^= y >>> 21; |
90 |
+ |
y ^= (y << 7); |
91 |
+ |
return y; |
92 |
+ |
} |
93 |
+ |
|
94 |
+ |
public static final long compute8InitialValue = 88172645463325252L; |
95 |
+ |
|
96 |
+ |
/** |
97 |
+ |
* Marsaglia xorshift for longs |
98 |
+ |
*/ |
99 |
+ |
public static long compute8(long x) { |
100 |
+ |
x ^= x << 13; |
101 |
+ |
x ^= x >>> 7; |
102 |
+ |
x ^= (x << 17); |
103 |
+ |
return x; |
104 |
+ |
} |
105 |
+ |
|
106 |
+ |
|
107 |
+ |
/** Multiplication-free RNG from Marsaglia "Xorshift RNGs" paper */ |
108 |
+ |
public static class MarsagliaRandom { |
109 |
+ |
int x; |
110 |
+ |
int y = 842502087; |
111 |
+ |
int z = (int)(3579807591L & 0xffff); |
112 |
+ |
int w = 273326509; |
113 |
+ |
public MarsagliaRandom(int seed) { x = seed; } |
114 |
+ |
public MarsagliaRandom() { this((int)System.nanoTime()); } |
115 |
+ |
public int next() { |
116 |
+ |
int t = x ^ (x << 11); |
117 |
+ |
x = y; |
118 |
+ |
y = z; |
119 |
+ |
z = w; |
120 |
+ |
return w = (w ^ (w >>> 19)) ^ (t ^ (t >>> 8)); |
121 |
+ |
} |
122 |
+ |
} |
123 |
|
|
124 |
|
/** |
125 |
|
* An actually useful random number generator, but unsynchronized. |