Java ThreadLocalRandom random int in a range

Description

Java ThreadLocalRandom random int in a range

import java.util.concurrent.ThreadLocalRandom;

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 w w .  ja  va 2s. co m*/

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



PreviousNext

Related