Miscellaneaous utility classes.
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. IntParallelCounterArrayAn array of approximate sets each represented using a Parallel counter. 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. XorGensRandomGeneratorA fast, high-quality 64-bit pseudorandom number generator described in “Some long-period random number generators using shift and xors”, ANZIAM Journal 48, C188−C202, 2007. XoRoShiRo128PlusPlusRandomA fast, all-purpose, rock-solid, small-state pseudorandom number generator. XoRoShiRo128PlusPlusRandomGeneratorA fast, all-purpose, rock-solid, small-state pseudorandom number generator. XoRoShiRo128PlusRandomA fast, high-quality pseudorandom number generator for floating-point generation. XoRoShiRo128PlusRandomGeneratorA fast, high-quality pseudorandom number generator for floating-point generation. XoRoShiRo128StarStarRandomA fast, all-purpose, rock-solid, small-state pseudorandom number generator. XoRoShiRo128StarStarRandomGeneratorA fast, all-purpose, rock-solid, small-state pseudorandom number generator. XorShift1024StarPhiRandom XorShift1024StarPhiRandomGeneratorA fast, high-quality pseudorandom number generator that combines a long-period instance of George Marsaglia's Xorshift generators (described in “Xorshift RNGs”, Journal of Statistical Software, 8:1−6, 2003) with a multiplication. XorShift1024StarRandom Deprecated.Please use
XorShift1024StarRandomGenerator Deprecated.Please use
XorShift128PlusRandom Deprecated.Please use
XorShift128PlusRandomGenerator Deprecated.Please use
XoShiRo256PlusPlusRandomA fast, all-purpose, rock-solid pseudorandom number generator. XoShiRo256PlusPlusRandomGeneratorA fast, all-purpose, rock-solid pseudorandom number generator. XoShiRo256PlusRandomA fast, rock-solid pseudorandom number generator for floating-point generation. XoShiRo256PlusRandomGeneratorA fast, rock-solid pseudorandom number generator for floating-point generation. XoShiRo256StarStarRandomA fast, all-purpose, rock-solid pseudorandom number generator. XoShiRo256StarStarRandomGeneratorA fast, all-purpose, rock-solid pseudorandom number generator.