Source Code : Generates a random integer inside the lo and hi interval

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Generates a random integer inside the lo and hi interval

  

/**
 *
 */
//package com.google.code.magja.utils;

/**
 * @author andre
 *
 */
public class MagjaNumberUtils {

  /**
   * Generates a random integer inside the lo and hi interval
   * @param lo
   * @param hi
   * @return the generated int
   */
  public static int randomInteger(int lo, int hi) {
    java.util.Random rn = new java.util.Random();
    int n = hi - lo + 1;
    int i = rn.nextInt() % n;
    if (i < 0) i = -i;
    return lo + i;
  }

}

   
    
  

Thank with us