All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.it.unimi.dsi.util.package-info Maven / Gradle / Ivy

Go to download

The DSI utilities are a mish mash of classes accumulated during the last ten years in projects developed at the DSI (Dipartimento di Scienze dell'Informazione, i.e., Information Sciences Department), now DI (Dipartimento di Informatica, i.e., Informatics Department), of the Universita` degli Studi di Milano.

There is a newer version: 2.7.3
Show newest version
/**
 * 

Miscellaneaous utility classes. * *

Pseudorandom number generators

* *

We provide a number of fast, high-quality PRNGs with different features. *

    *
  • {@link it.unimi.dsi.util.XoRoShiRo128PlusRandom xoroshiro128+} is a fast, top-quality generator. * It has strong statistical properties and it is the fastest generator we provide. Its period (2128 − 1) is sufficient * for any application with a reasonable amount of parallelism. It is our suggestion for an all-purpose generator. *
  • {@link it.unimi.dsi.util.XorShift128PlusRandom xorshift128+} is a fast, high-quality generator, but it has been superseded * by xoroshiro128+, which is better under every respect. It is presently used in the JavaScript engines of * Chrome, * Firefox and * Safari, and it is the * default generator in Erlang. *
  • {@link it.unimi.dsi.util.SplitMix64Random SplitMix64} is a fast, top-quality generator, but it has a relatively short period (264) so it should * not be used to generate very long sequences (the rule of thumb to have a period greater than the square of the length of the sequence you want to generate). * It is a non-splittable version of Java 8's SplittableRandom, * and thus conceptually identical to Java 8's * ThreadLocalRandom (note that Java 7's version * was identical to {@link java.util.Random}, instead). We use it to initialize the state of all other generators starting from a 64-bit seed. *
  • {@link it.unimi.dsi.util.XorShift1024StarRandom xorshift1024*} is fast, has good quality * and provides a long period (21024 − 1) for massive parallel computations. *
* *

{@link it.unimi.dsi.util.XoRoShiRo128PlusRandom xoroshiro128+}, {@link it.unimi.dsi.util.XorShift128PlusRandom xorshift128+} and * {@link it.unimi.dsi.util.XorShift1024StarRandom xorshift1024*} provide * {@linkplain it.unimi.dsi.util.XoRoShiRo128PlusRandom#jump() jump functions} which make it possible to generate long non-overlapping sequences, * and {@linkplain it.unimi.dsi.util.XoRoShiRo128PlusRandom#split() split functions} in the spirit of {@link java.util.SplittableRandom SplittableRandom}. * *

A table summarizing timings is provided below. Note that we test several different method parameters to highlight * the different strategies used to generate numbers in a range, as the rejection-based algorithm used by all generators * can be based on integer or long inputs, and the results are quite different. For example, on modern, 64-bit CPUs Java's * strategy of applying rejection to 32-bit integers does not pay off (see the timings for nextInt(230 + 1)). * *

The timings are very different from previous versions, but they * should be more reliable, as they are now obtained by means of * 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} * ThreadLocalRandom * SplittableRandom * {@link it.unimi.dsi.util.SplitMix64RandomGenerator SplitMix64} * {@link it.unimi.dsi.util.XoRoShiRo128PlusRandom xoroshiro128+} * {@link it.unimi.dsi.util.XorShift128PlusRandom xorshift128+} * {@link it.unimi.dsi.util.XorShift1024StarRandom xorshift1024*} * *
nextInt() 8.2721.8601.9991.8961.9362.0073.127 *
nextLong() 17.5491.8862.1232.0541.9942.0123.106 *
nextDouble() 17.5422.6863.0683.0042.5972.7403.835 *
nextInt(100000) 8.2853.1633.7693.7133.0703.2644.753 *
nextInt(229+228) 12.6347.9398.5744.1303.3473.5865.152 *
nextInt(230) 8.2691.8862.1482.2261.9782.5803.229 *
nextInt(230 + 1) 22.15215.64516.4833.8373.2443.5285.004 *
nextInt(230 + 229) 12.5817.9238.5784.0923.3443.5725.138 *
nextLong(1000000000000) 3.4824.0603.9233.3043.6045.064 *
nextLong(262 + 1) 16.09016.86416.81113.80514.87818.197 * *
* *

The quality of all generators we provide is very high: for instance, they perform better than WELL1024a * or MT19937 (AKA the Mersenne Twister) in the TestU01 BigCrush test suite. * More details can be found on the xoroshiro+/xorshift*/xorshift+ generators and the PRNG shootout page. * *

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). * In particular, {@link java.util.Random#nextDouble() nextDouble()} and {@link java.util.Random#nextFloat() nextFloat()} * use a multiplication-free conversion. * *

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;





© 2015 - 2025 Weber Informatics LLC | Privacy Policy