src.it.unimi.dsi.util.package-info Maven / Gradle / Ivy
Show all versions of dsiutils Show documentation
/**
* Miscellaneaous utility classes.
*
*
Pseudorandom number generators
*
* We provide a number of fast, high-quality PRNGs with different features. You can get detailed
* information about the generators at our PRNG page, together
* with a reasoned guide to the choice of the generator that's right for you.
*
*
A table summarizing timings is provided below. The timings were measured on an
* Intel® Core™ i7-8700B CPU @3.20GHz using
* JMH microbenchmarks. The JMH timings were decreased by 1ns, as
* using the low-level {@code perfasm} profiler the JMH overhead was estimated at ≈1ns per call.
*
*
*
* {@link java.util.Random Random}
* {@link java.util.concurrent.ThreadLocalRandom ThreadLocalRandom}
* {@link java.util.SplittableRandom SplittableRandom}
* {@link it.unimi.dsi.util.SplitMix64RandomGenerator SplitMix64}
* {@link it.unimi.dsi.util.XoRoShiRo128PlusPlusRandom xoroshiro128++
}
* {@link it.unimi.dsi.util.XoRoShiRo128StarStarRandom xoroshiro128**
}
* {@link it.unimi.dsi.util.XoRoShiRo128PlusRandom xoroshiro128+
}
* {@link it.unimi.dsi.util.XoShiRo256PlusPlusRandom xoshiro256++
}
* {@link it.unimi.dsi.util.XoShiRo256StarStarRandom xoshiro256**
}
* {@link it.unimi.dsi.util.XoShiRo256PlusRandom xoshiro256+
}
* {@link it.unimi.dsi.util.XorShift1024StarPhiRandom xorshift1024*φ
}
*
* nextLong() 14.419 1.252 1.283 1.241 1.428 1.574 1.295 1.738 1.884 1.653 1.901
* nextInt(100000) 6.715 2.045 2.499 2.543 2.336 2.594 1.202 2.607 2.954 2.367 3.119
* nextDouble() 14.458 1.876 2.161 2.176 1.918 2.219 1.853 2.304 2.503 2.112 2.755
*
*
* Note that generators that are extremely fast in C, such as xoshiro256+
, do not perform particularly well in Java, most likely
* because of the cost of accessing variables, which rises as the size of the state space grows. Indeed,
* smaller-state generators are faster. Moreover, generators based on the ++
* scrambler are slightly faster than those based on the **
scrambler, contrarily to what happens in C.
*
*
For each generator, we provide a version that extends {@link java.util.Random}, overriding (as usual) the {@link java.util.Random#next(int) next(int)} method. Nonetheless,
* since the generators are all inherently 64-bit also {@link java.util.Random#nextInt() nextInt()}, {@link java.util.Random#nextFloat() nextFloat()},
* {@link java.util.Random#nextLong() nextLong()}, {@link java.util.Random#nextDouble() nextDouble()}, {@link java.util.Random#nextBoolean() nextBoolean()}
* and {@link java.util.Random#nextBytes(byte[]) nextBytes(byte[])} have been overridden for speed (preserving, of course, {@link java.util.Random}'s semantics).
*
*
If you do not need an instance of {@link java.util.Random}, or if you need a {@link org.apache.commons.math3.random.RandomGenerator} to use
* with Commons Math, there is for each generator a corresponding {@link org.apache.commons.math3.random.RandomGenerator RandomGenerator}
* implementation, which indeed we suggest to use in general if you do not need a generator implementing {@link java.util.Random}.
*/
package it.unimi.dsi.util;