tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Uncommons Maths > XOR Shift Random Number Generator

XOR Shift 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 XORShiftRNG class.

File Name  :  
com/bethecoder/tutorials/uncommons/XORShiftRNGTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.uncommons;

import java.util.Arrays;

import org.uncommons.maths.random.XORShiftRNG;

public class XORShiftRNGTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    XORShiftRNG rand = new XORShiftRNG();
    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,
[-14, -97, 118, -47, -24, -8, -45, -4, -14, 63, -80, 43, -23, 117, 67, -108, -43, 90, 27, 24]
-863523012
0.3501870312182872
1.3469134434821788
false



 
  


  
bl  br