
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to generate random numbers
The java.util.Random class instance is used to generate a stream of pseudorandom numbers.
- The class uses a 48-bit seed, which is modified using a linear congruential formula.
- The algorithms implemented by class Random use a protected utility method that on each invocation can supply up to 32 pseudo randomly generated bits.
- The nextInt() method of this class is used to get the next pseudorandom, uniformly distributed int value from this random number generator's sequence.
Example
import java.util.*; public class RandomNumberGeneration { public static void main( String args[] ) { // create random object Random randomno = new Random(); Scanner sc = new Scanner(System.in); System.out.println("How many random numbers do you need :"); int n= sc.nextInt(); // check next int value for(int i=0; i<n; i++){ System.out.println(randomno.nextInt()); } } }
Output
How many random numbers do you need : 4 709914869 -1882917719 -758130689 637944833
- Related Questions & Answers
- Java Program to generate random numbers string
- Java Program to generate n distinct random numbers
- Java Program to generate random numbers with no duplicates
- C# program to generate secure random numbers
- Generate Random Integer Numbers in Java
- How to generate large random numbers in Java?
- Generate Random Long type numbers in Java
- Generate random numbers in Arduino
- Generate 10 random four-digit numbers in Java
- Generate random numbers using C++11 random library
- C++ Program to Generate Random Numbers Using Middle Square Method
- C++ Program to Generate Random Numbers Using Probability Distribution Function
- Java Program to generate random number with restrictions
- Python module to Generate secure random numbers
- How does Python generate random numbers?
Advertisements