1033 * The increment for generating probe values.
1034 */
1035 private static final int PROBE_INCREMENT = 0x9e3779b9;
1036
1037 /**
1038 * The increment of seeder per new instance.
1039 */
1040 private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
1041
1042 // Constants from SplittableRandom
1043 private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53)
1044 private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
1045
1046 // IllegalArgumentException messages
1047 static final String BAD_BOUND = "bound must be positive";
1048 static final String BAD_RANGE = "bound must be greater than origin";
1049 static final String BAD_SIZE = "size must be non-negative";
1050
1051 // Unsafe mechanics
1052 private static final Unsafe U = Unsafe.getUnsafe();
1053 private static final long SEED;
1054 private static final long PROBE;
1055 private static final long SECONDARY;
1056 private static final long THREADLOCALS;
1057 private static final long INHERITABLETHREADLOCALS;
1058 private static final long INHERITEDACCESSCONTROLCONTEXT;
1059 static {
1060 try {
1061 SEED = U.objectFieldOffset
1062 (Thread.class.getDeclaredField("threadLocalRandomSeed"));
1063 PROBE = U.objectFieldOffset
1064 (Thread.class.getDeclaredField("threadLocalRandomProbe"));
1065 SECONDARY = U.objectFieldOffset
1066 (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
1067 THREADLOCALS = U.objectFieldOffset
1068 (Thread.class.getDeclaredField("threadLocals"));
1069 INHERITABLETHREADLOCALS = U.objectFieldOffset
1070 (Thread.class.getDeclaredField("inheritableThreadLocals"));
1071 INHERITEDACCESSCONTROLCONTEXT = U.objectFieldOffset
1072 (Thread.class.getDeclaredField("inheritedAccessControlContext"));
1073 } catch (ReflectiveOperationException e) {
1074 throw new Error(e);
1075 }
1076 }
1077
1078 /** Rarely-used holder for the second of a pair of Gaussians */
1079 private static final ThreadLocal<Double> nextLocalGaussian =
1080 new ThreadLocal<>();
1081
1082 /** Generates per-thread initialization/probe field */
1083 private static final AtomicInteger probeGenerator = new AtomicInteger();
1084
1085 /** The common ThreadLocalRandom */
1086 static final ThreadLocalRandom instance = new ThreadLocalRandom();
1087
1088 /**
1089 * The next seed for default constructors.
1090 */
1091 private static final AtomicLong seeder
1092 = new AtomicLong(mix64(System.currentTimeMillis()) ^
1093 mix64(System.nanoTime()));
1094
1095 // at end of <clinit> to survive static initialization circularity
1096 static {
|
1033 * The increment for generating probe values.
1034 */
1035 private static final int PROBE_INCREMENT = 0x9e3779b9;
1036
1037 /**
1038 * The increment of seeder per new instance.
1039 */
1040 private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL;
1041
1042 // Constants from SplittableRandom
1043 private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53)
1044 private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24)
1045
1046 // IllegalArgumentException messages
1047 static final String BAD_BOUND = "bound must be positive";
1048 static final String BAD_RANGE = "bound must be greater than origin";
1049 static final String BAD_SIZE = "size must be non-negative";
1050
1051 // Unsafe mechanics
1052 private static final Unsafe U = Unsafe.getUnsafe();
1053 private static final long SEED = U.objectFieldOffset
1054 (Thread.class, "threadLocalRandomSeed");
1055 private static final long PROBE = U.objectFieldOffset
1056 (Thread.class, "threadLocalRandomProbe");
1057 private static final long SECONDARY = U.objectFieldOffset
1058 (Thread.class, "threadLocalRandomSecondarySeed");
1059 private static final long THREADLOCALS = U.objectFieldOffset
1060 (Thread.class, "threadLocals");
1061 private static final long INHERITABLETHREADLOCALS = U.objectFieldOffset
1062 (Thread.class, "inheritableThreadLocals");
1063 private static final long INHERITEDACCESSCONTROLCONTEXT = U.objectFieldOffset
1064 (Thread.class, "inheritedAccessControlContext");
1065
1066 /** Rarely-used holder for the second of a pair of Gaussians */
1067 private static final ThreadLocal<Double> nextLocalGaussian =
1068 new ThreadLocal<>();
1069
1070 /** Generates per-thread initialization/probe field */
1071 private static final AtomicInteger probeGenerator = new AtomicInteger();
1072
1073 /** The common ThreadLocalRandom */
1074 static final ThreadLocalRandom instance = new ThreadLocalRandom();
1075
1076 /**
1077 * The next seed for default constructors.
1078 */
1079 private static final AtomicLong seeder
1080 = new AtomicLong(mix64(System.currentTimeMillis()) ^
1081 mix64(System.nanoTime()));
1082
1083 // at end of <clinit> to survive static initialization circularity
1084 static {
|