Mersenne Twister Random Number Generator
Uncommons Maths is a java library with nice math utilities and random number generators.
This requires the library uncommons-maths-1.2.2.jar to be in classpath.
The following example shows using MersenneTwisterRNG class.
package com.bethecoder.tutorials.uncommons;
import java.util.Arrays;
import org.uncommons.maths.random.MersenneTwisterRNG;
public class MersenneTwisterRNGTest {
/**
* @param args
*/
public static void main ( String [] args ) {
MersenneTwisterRNG rand = new MersenneTwisterRNG () ;
System.out.println ( Arrays.toString ( rand.getSeed ())) ;
System.out.println ( rand.nextInt ()) ;
System.out.println ( rand.nextDouble ()) ;
System.out.println ( rand.nextGaussian ()) ;
System.out.println ( rand.nextBoolean ()) ;
}
}
It gives the following output,
[-52, 102, 70, -99, -103, 83, -125, -123, -30, -116, 52, -113, 67, -77, 116, -75]
1075206337
0.6441442843890055
-1.4486417460662737
false