logo image

Generating random number in Java



This program shows you how to generate random number in Java

import java.util.Random;

public class RandomNumber {
	public static void main(String[] args) {

		Random random = new Random();
		System.out.println("Random Numbers between 0 & 10: " + random.nextInt(10));
		System.out.println("Random Numbers between 0 & 100: " + random.nextInt(100));

	}

}

Output:

Random Numbers between 0 & 10: 4
Random Numbers between 0 & 100: 36