Random class in Java to generate random numbers here is a simple example to generate Random numbers. Generate the random number between 100.


import the random class

import java.util.Random;


Example:


import java.util.Random;

public class JavaApplication {

    public static void main(String[] args) {

        Random objGenerator = new Random();
        for (int iCount = 0; iCount < 10; iCount++) {

            //only int
            int randomNumber = objGenerator.nextInt(100);
            System.out.println("Random No : " + randomNumber);
        }

    }
    
}


Output:

run:
Random No : 42
Random No : 61
Random No : 18
Random No : 78
Random No : 24
Random No : 24
Random No : 3
Random No : 6
Random No : 87
Random No : 35