class SplittableRandom
Martin Buchholz
martinrb at google.com
Mon Jul 15 16:59:16 UTC 2013
If we make the wraparound point for seeds Long.MIN_VALUE instead of 0L,
then we can optimize addGammaModGeorge. Any reason the following won't
work?
--- src/main/java/util/SplittableRandom.java 14 Jul 2013 08:06:49 -0000 1.10
+++ src/main/java/util/SplittableRandom.java 15 Jul 2013 16:25:42 -0000
@@ -222,10 +222,10 @@
*/
private static long addGammaModGeorge(long s, long g) {
long p = s + g;
- if (Long.compareUnsigned(p, g) >= 0)
+ if (p > s)
return p;
- long q = p - 13L;
- return (Long.compareUnsigned(p, 13L) >= 0) ? q : (q + g);
+ p -= 13L;
+ return (p < s) ? p : p + g;
}
/**
Also, if gamma is much less than 2^64 (say 2^56; that number of gammas
"should be enough for anybody"), then the above will be a little more
efficient since the wraparound code will be rare and well-predicted. The
bits that become available as a result can then be optionally donated to
the seed space!
Have we run DieHarder tests against adversarial gamma values, that provide
as few bits as possible? Most obviously, try gamma == 16.
More information about the core-libs-dev
mailing list