Package it.unimi.dsi.util

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-7700 CPU @ 3.60GHz (Kaby Lake), and they are now obtained by means of JMH microbenchmarks. The JMH timings were decreased by 1ns, as using the low-level perfasm profiler the JMH overhead was estimated at ≈1ns per call.

Random ThreadLocalRandom SplittableRandom SplitMix64 xoroshiro128** xoroshiro128+ xoshiro256** xoshiro256+ xorshift1024*φ
nextLong() 15.8251.4501.4821.5531.8501.5242.1351.8762.157
nextInt(100000) 7.3912.4002.8052.8582.9332.4073.2662.7543.509
nextDouble() 15.8252.1252.4342.4532.5032.1052.8022.3823.077

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.

For each generator, we provide a version that extends Random, overriding (as usual) the next(int) method. Nonetheless, since the generators are all inherently 64-bit also nextInt(), nextFloat(), nextLong(), nextDouble(), nextBoolean() and nextBytes(byte[]) have been overridden for speed (preserving, of course, Random's semantics).

If you do not need an instance of Random, or if you need a RandomGenerator to use with Commons Math, there is for each generator a corresponding RandomGenerator implementation, which indeed we suggest to use in general if you do not need a generator implementing Random.

Skip navigation links