/// <summary> /// Pseudo-randomly advances and records the given probe value for the /// given thread. /// Duplicated from ThreadLocalRandom because of packaging restrictions. /// </summary> internal static int AdvanceProbe(int probe) { probe ^= probe << 13; // xorshift probe ^= (int)((uint)probe >> 17); probe ^= probe << 5; UNSAFE.putInt(Thread.CurrentThread, PROBE, probe); return(probe); }
/// <summary> /// Returns the pseudo-randomly initialized or updated secondary seed. /// Copied from ThreadLocalRandom due to package access restrictions. /// </summary> internal static int NextSecondarySeed() { int r; Thread t = Thread.CurrentThread; if ((r = UNSAFE.getInt(t, SECONDARY)) != 0) { r ^= r << 13; // xorshift r ^= (int)((uint)r >> 17); r ^= r << 5; } else if ((r = java.util.concurrent.ThreadLocalRandom.Current().NextInt()) == 0) { r = 1; // avoid zero } UNSAFE.putInt(t, SECONDARY, r); return(r); }