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