@Override public float nextFloat() { return (nextLong() >>> 40) * 0x1.0p-24f; }
@Override public boolean nextBoolean() { return nextLong() < 0; }
@Override public int nextInt() { return (int)(nextLong() >>> 32); }
@Override public int nextInt(final int n) { return (int)nextLong(n); }
@Override public double nextDouble() { return (nextLong() >>> 11) * 0x1.0p-53; }
private XoRoShiRo128PlusRandomGenerator jump(final long[] jump) { long s0 = 0; long s1 = 0; for(int i = 0; i < jump.length; i++) for(int b = 0; b < 64; b++) { if ((jump[i] & 1L << b) != 0) { s0 ^= this.s0; s1 ^= this.s1; } nextLong(); } this.s0 = s0; this.s1 = s1; return this; }
/** Returns a random seed generated by taking the output of a {@link XoRoShiRo128PlusRandomGenerator} * (seeded at startup with {@link System#nanoTime()}) and xoring it with {@link System#nanoTime()}. * * @return a reasonably good random seed. */ public static long randomSeed() { final long x; synchronized(seedUniquifier) { x = seedUniquifier.nextLong(); } return x ^ System.nanoTime(); }
@Override public void nextBytes(final byte[] bytes) { int i = bytes.length, n = 0; while(i != 0) { n = Math.min(i, 8); for (long bits = nextLong(); n-- != 0; bits >>= 8) bytes[--i] = (byte)bits; } }
/** Returns a pseudorandom uniformly distributed {@code long} value * between 0 (inclusive) and the specified value (exclusive), drawn from * this random number generator's sequence. The algorithm used to generate * the value guarantees that the result is uniform, provided that the * sequence of 64-bit values produced by this generator is. * * @param n the positive bound on the random number to be returned. * @return the next pseudorandom {@code long} value between {@code 0} (inclusive) and {@code n} (exclusive). */ public long nextLong(final long n) { if (n <= 0) throw new IllegalArgumentException("illegal bound " + n + " (must be positive)"); long t = nextLong(); final long nMinus1 = n - 1; // Shortcut for powers of two--high bits if ((n & nMinus1) == 0) return (t >>> Long.numberOfLeadingZeros(nMinus1)) & nMinus1; // Rejection-based algorithm to get uniform integers in the general case for (long u = t >>> 1; u + nMinus1 - (t = u % n) < 0; u = nextLong() >>> 1); return t; }
/** * Returns the next pseudorandom, uniformly distributed * {@code double} value between {@code 0.0} and * {@code 1.0} from this random number generator's sequence, * using a fast multiplication-free method which, however, * can provide only 52 significant bits. * * <p>This method is faster than {@link #nextDouble()}, but it * can return only dyadic rationals of the form <var>k</var> / 2<sup>−52</sup>, * instead of the standard <var>k</var> / 2<sup>−53</sup>. Before * version 2.4.1, this was actually the standard implementation of * {@link #nextDouble()}, so you can use this method if you need to * reproduce exactly results obtained using previous versions. * * <p>The only difference between the output of this method and that of * {@link #nextDouble()} is an additional least significant bit set in half of the * returned values. For most applications, this difference is negligible. * * @return the next pseudorandom, uniformly distributed {@code double} * value between {@code 0.0} and {@code 1.0} from this * random number generator's sequence, using 52 significant bits only. * * @since 2.4.1 */ public double nextDoubleFast() { return Double.longBitsToDouble(0x3FFL << 52 | nextLong() >>> 12) - 1.0; }
public static void main(final String[] arg) { final long n = Long.parseLong(arg[0]); long x = 0; final ProgressLogger pl = new ProgressLogger(); final XoRoShiRo128PlusRandomGenerator r = new XoRoShiRo128PlusRandomGenerator(0); for(int k = 10; k-- != 0;) { pl.start("Measuring..."); for (long i = n; i-- != 0;) x ^= r.nextLong(); pl.done(n); if (x == 0) System.out.println(x); } } }
add(i, random.nextLong());
/** * Removes a bucket. * * @param bucket the bucket to be removed. * @return false if the bucket was not present. */ @SuppressWarnings("unchecked") public boolean remove( final T bucket ) { if ( !sizes.containsKey( bucket ) ) return false; final XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator( bucket.hashCode() ); final int size = sizes.removeInt( bucket ); for ( int i = 0; i < size * REPLICAE_PER_BUCKET; i++ ) { final long point = random.nextLong(); final Object o = replicae.remove( point ); if ( o instanceof ObjectAVLTreeSet ) { if ( DEBUG ) System.err.println( "Removing from " + point + " conflict set..." ); final ObjectAVLTreeSet<T> conflictSet = (ObjectAVLTreeSet<T>)o; conflictSet.remove( bucket ); if ( conflictSet.size() > 1 ) replicae.put( point, conflictSet ); else replicae.put( point, conflictSet.first() ); } else if ( o != null && ( (T)o ).compareTo( bucket ) != 0 ) replicae.put( point, o ); } return true; }
if (keys == null) throw new IllegalArgumentException("If you do not provide a chunked hash store, you must provide the keys"); chunkedHashStore = new ChunkedHashStore<>(transform, tempDir, -1, pl); chunkedHashStore.reset(r.nextLong()); if (values == null || indirect) chunkedHashStore.addAll(keys.iterator()); else chunkedHashStore.addAll(keys.iterator(), values.iterator()); if (duplicates++ > 3) throw new IllegalArgumentException("The input list contains duplicates"); LOGGER.warn("Found duplicate. Recomputing triples..."); chunkedHashStore.reset(r.nextLong()); pl.itemsName = "keys"; if (values == null || indirect) chunkedHashStore.addAll(keys.iterator());
final long point = random.nextLong();