In Java, there are three ways to generate random numbers:

  • java.util.Random class
  • Math.random method
  • ThreadLocalRandom class
BY Best Interview Question ON 03 Apr 2020


This is done Using java.util.Random class:
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(100) + 1;
//100 is the maximum and the 1 is our minimum.