Pseudorandom number generators
Warning: before release 2.6.3, the
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
now different, and the result of
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
perfasm profiler the JMH overhead was estimated at ≈1ns per call.
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
Random, overriding (as usual) the
next(int) method. Nonetheless,
since the generators are all inherently 64-bit also
nextBytes(byte) have been overridden for speed (preserving, of course,
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
implementation, which indeed we suggest to use in general if you do not need a generator implementing
Class Summary Class Description AbstractPrefixMapAn abstract implementation of a prefix map. BloomFilter<T>A Bloom filter. ByteBufferLongBigList CircularCharArrayBufferA circular char buffer that can be used to implement a sliding window over a text. FrontCodedStringListCompact storage of strings using front-coding compression (a.k.a. compression by prefix omission). HyperLogLogCounterArrayAn array of approximate sets each represented using a HyperLogLog counter. ImmutableBinaryTrie<T>An immutable implementation of binary tries. ImmutableBinaryTrie.NodeA node in the trie. ImmutableExternalPrefixMapAn immutable prefix map mostly stored in external memory. IntervalAn interval of integers. IntervalsA class providing static methods and objects that do useful things with intervals. KahanSummationKahan's summation algorithm encapsulated in an object. LiterallySignedStringMapA string map based on a function signed using the original list of strings. LongIntervalAn interval of longs. LongIntervalsA class providing static methods and objects that do useful things with intervals. PermutedFrontCodedStringListA
FrontCodedStringListwhose indices are permuted.
Properties SemiExternalGammaListProvides semi-external random access to a list of γ-encoded integers. ShiftAddXorSignedStringMap Deprecated.There are much better and faster hash functions. SplitMix64RandomA fast, high-quality, non-splittable version of the SplitMix pseudorandom number generator used by
SplitMix64RandomGeneratorA fast, high-quality, non-splittable version of the SplitMix pseudorandom number generator used by
StringMaps StringMaps.SynchronizedPrefixMap<S extends CharSequence> StringMaps.SynchronizedStringMap<S extends CharSequence> TernaryIntervalSearchTreeTernary interval search trees. TextPatternQuickSearch matching against a constant string. XoRoShiRo128PlusPlusRandom XoRoShiRo128PlusPlusRandomGenerator XoRoShiRo128PlusRandomA fast, high-quality pseudorandom number generator for floating-point generation. XoRoShiRo128PlusRandomGeneratorA fast, high-quality pseudorandom number generator for floating-point generation. XoRoShiRo128StarStarRandom XoRoShiRo128StarStarRandomGenerator XorShift1024StarPhiRandom XorShift1024StarPhiRandomGenerator XorShift1024StarRandom Deprecated.Please use
XorShift1024StarRandomGenerator Deprecated.Please use
XorShift128PlusRandom Deprecated.Please use
XorShift128PlusRandomGenerator Deprecated.Please use
XoShiRo256PlusPlusRandom XoShiRo256PlusPlusRandomGenerator XoShiRo256PlusRandomA fast, rock-solid pseudorandom number generator for floating-point generation. XoShiRo256PlusRandomGeneratorA fast, rock-solid pseudorandom number generator for floating-point generation. XoShiRo256StarStarRandom XoShiRo256StarStarRandomGenerator