Write a Java program to generate random numbers using Random()

By | 09.02.2017

Java program to generate random numbers


To generate random numbers in Java programming, you have to create the object of Random class available in the java.util.Random package as shown in the following program.

Following Java program to generate random numbers: This code generates random numbers in range 0 to 10000

SOURCE CODE ::

import java.util.Scanner;
import java.util.Random;
 
public class Random_numbers{
  public static void main(String[] args) {
    int c;
    Random t = new Random();
 
    for (c = 1; c <= 15; c++) {
      System.out.println(t.nextInt(10000));
    }
  }
}

 

OUTPUT ::

7307
3364
9601
6944
1573
7080
199
1261
3046
5751
1963
9607
6334
8294
4390

 

 

0 0 votes
Article Rating
Category: Java Programming Number Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments