/** Returns a copy of this generator. The sequences produced by this generator and by the returned generator will be identical. * * <p>This method is particularly useful in conjunction with the {@link #jump()} method: by calling repeatedly * {@link #jump() jump().copy()} over a generator it is possible to create several generators producing non-overlapping sequences. * * @return a copy of this generator. */ public XoRoShiRo128PlusRandomGenerator copy() { return new XoRoShiRo128PlusRandomGenerator(s0, s1); }
@Override public int nextInt() { return (int)(nextLong() >>> 32); }
/** The jump function for this generator. It is equivalent to 2<sup>64</sup> * calls to {@link #nextLong()}; it can be used to generate 2<sup>64</sup> * non-overlapping subsequences for parallel computations. * * @return this generator. * @see #copy() */ public XoRoShiRo128PlusRandomGenerator jump() { return jump(JUMP); }
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); } } }
/** Creates a new generator using a given seed. * * @param seed a seed for the generator. */ public XoRoShiRo128PlusRandomGenerator(final long seed) { setSeed(seed); }
@Override public int nextInt() { curr++; outdegree = bg.sample(); successors.clear(); if (! loops) successors.add(curr); for(int i = 0; i < outdegree; i++) while(! successors.add(random.nextInt(n))); if (! loops) successors.remove(curr); successorArray = IntArrays.grow(successorArray, outdegree); successors.toArray(successorArray); IntArrays.quickSort(successorArray, 0, outdegree); return curr; }
XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator(seed); 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; }
/** * Returns a new instance that shares no mutable state * with this instance. The sequence generated by the new instance * depends deterministically from the state of this instance, * but the probability that the sequence generated by this * instance and by the new instance overlap is negligible. * * @return the new instance. */ public XoRoShiRo128PlusRandomGenerator split() { final XoRoShiRo128PlusRandomGenerator split = new XoRoShiRo128PlusRandomGenerator(); split.s0 = HashCommon.murmurHash3(s0); split.s1 = HashCommon.murmurHash3(s1); return split; }
@Override public int nextInt(final int n) { return (int)nextLong(n); }
/** The long-jump function for this generator. It is equivalent to 2<sup>96</sup> * calls to {@link #nextLong()}; it can be used to generate 2<sup>32</sup> starting points, * from each of which {@link #jump()} will generate 2<sup>32</sup> non-overlapping * subsequences for parallel distributed computations. * * @return this generator. * @see #copy() */ public XoRoShiRo128PlusRandomGenerator longJump() { return jump(LONG_JUMP); }
sizes.put( bucket, weight ); final XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator( bucket.hashCode() ); final long point = random.nextLong();
/** Checks that this store has no duplicate triples, and try to rebuild if this fails to happen. * * @param iterable the elements with which the store will be refilled if there are duplicate triples. * @param values the values that will be associated with the elements returned by <code>iterable</code>. * @throws IllegalArgumentException if after a few trials the store still contains duplicate triples. */ public void checkAndRetry(final Iterable<? extends T> iterable, final LongIterable values) throws IOException { final RandomGenerator random = new XoRoShiRo128PlusRandomGenerator(); int duplicates = 0; for(;;) try { check(); break; } catch (final DuplicateException e) { if (duplicates++ > 3) throw new IllegalArgumentException("The input list contains duplicates"); LOGGER.warn("Found duplicate. Recomputing triples..."); reset(random.nextLong()); addAll(iterable.iterator(), values.iterator()); } checkedForDuplicates = true; }
@Override public float nextFloat() { return (nextLong() >>> 40) * 0x1.0p-24f; }
pl.displayLocalSpeed = true; pl.displayFreeMemory = true; final XoRoShiRo128PlusRandomGenerator r = new XoRoShiRo128PlusRandomGenerator(); pl.itemsName = "keys"; final boolean givenChunkedHashStore = chunkedHashStore != null; 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());
@Override public NodeIterator nodeIterator() { return new NodeIterator() { private final XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator(seed);
@Override public boolean nextBoolean() { return nextLong() < 0; }
pl.displayLocalSpeed = true; pl.displayFreeMemory = true; final RandomGenerator r = new XoRoShiRo128PlusRandomGenerator(); pl.itemsName = "keys";
@Override public double nextDouble() { return (nextLong() >>> 11) * 0x1.0p-53; }
pl.displayLocalSpeed = true; pl.displayFreeMemory = true; final RandomGenerator r = new XoRoShiRo128PlusRandomGenerator(); pl.itemsName = "keys";