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 mishmash of classes accumulated during the last twenty 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

* *

Warning: before release 2.6.3, the {@code split()} method of all generators * would not alter the state of the caller, and it would return instances initialized in the same * way if called multiple times. This was a major mistake in the implementation and it has been fixed, * but as a consequence the output of the caller after a call to {@code split()} is * now different, and the result of {@code split()} is initialized in a different way. * *

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. * *

* *
Timings in nanoseconds for a few generators
* {@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.4191.2521.2831.2411.4281.5741.2951.7381.8841.6531.901 *
nextInt(100000) 6.7152.0452.4992.5432.3362.5941.2022.6072.9542.3673.119 *
nextDouble() 14.4581.8762.1612.1761.9182.2191.8532.3042.5032.1122.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;





© 2015 - 2024 Weber Informatics LLC | Privacy Policy