Java Random generate random int in a range

Description

Java Random generate random int in a range

import java.util.Random;

public class Main {
  public static void main(String[] args) {
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
    System.out.println(randomMinMax(5, 10));
  }//from w  w  w . j a v a 2  s. com

  public static int randomMinMax(int min, int max) {
    return new Random().nextInt(max - min + 1) + min;
  }
}



PreviousNext

Related