Apache Commons logo Apache Commons RNG

Apache Commons RNG: Random Numbers Generators

Commons RNG provides implementations of pseudo-random numbers generators that are either faster or of higher quality (and sometimes both) than java.util.Random.

Casual use is as simple as:

import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;

// Instantiate a "Mersenne-Twister" generator with a factory method.
UniformRandomProvider rng = RandomSource.create(RandomSource.MT);

// Use it to produce a floating-point value between 0 and 1.
double random = rng.nextDouble();

For more examples and more advanced usage, see the userguide.

Commons RNG is intended to be a repository of pure Java implementations of random number generators that produce deterministic sequences. The current design has made no provision for features generally needed for cryptography applications (e.g. strong unpredictability).

The emphasis is on state-of-the-art generators that pass stringent uniformity tests such as TU01 and Dieharder. Weaker algorithms, with known shortcomings, are also provided (for reference or due to their historical importance) but their use is best avoided in new applications.

Download Apache Commons RNG


Download the latest release of Apache Commons RNG.