Java Random generate random int in a range via Stream

Description

Java Random generate random int in a range via Stream

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 .  ja  va2  s  .c o m*/

  public static int randomMinMax(int min, int max) {
    return new Random().ints(min, (max + 1)).findFirst().getAsInt();
  }

}



PreviousNext

Related