Java SecureRandom generate random int in a range

Description

Java SecureRandom generate random int in a range

import java.security.SecureRandom;

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));
  }// w ww . j  a  va 2 s .  c  o m

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



PreviousNext

Related