Generate Random Number in Java

Generate Random Number in Java

A random number is a value that is created without any pattern or order.

Here you will learn to Generate Random Number program in Java using two different programs. To make a Random number generators in java, we will use random () method.

1. Generate a Random Number

2. Generate n Random numbers in a given range

Program 1 – Generate Random Number

Output

C:\CodeRevise\java>javac RandomNumber.java

C:\CodeRevise\java>java RandomNumber
Random Number: 82

C:\CodeRevise\java>java RandomNumber
Random Number: 50

C:\CodeRevise\java>java RandomNumber
Random Number: 84

C:\CodeRevise\java>java RandomNumber
Random Number: 9

Program 2 – Generate n Random numbers

Output

C:\CodeRevise\java>javac RandomNumber.java

C:\CodeRevise\java>java RandomNumber
How many Random number you want to generate : 7
Enter upper limit : 100
7 Random Numbers are :
42
53
99
4
61
1
97

 

 

Check out our other Java Programming Examples

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top