- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate Random double type number in Java
In order to generate Random double type numbers in Java, we use the nextDouble() method of the java.util.Random class. This returns the next random double value between 0.0 (inclusive) and 1.0 (exclusive) from the random generator sequence.
Declaration - The java.util.Random.nextDouble() method is declared as follows −
public float nextDouble()
Let us see a program to generate random double type numbers in Java −
Example
import java.util.Random; public class Example { public static void main(String[] args) { Random rd = new Random(); // creating Random object System.out.println(rd.nextDouble()); // displaying a random double value between 0.0 & 1.0 } }
Output
0.40755033612457214
Note - The output might vary on Online Compilers.
- Related Articles
- Generate Random Float type number in Java
- Generate Random Long type numbers in Java
- Java Program to generate random number with restrictions
- Generate Random boolean in Java
- Generate Random bytes in Java
- Convert a String to a double type number in Java
- Format double type in Java
- Java Program to generate custom random number -1 or 1
- Java Program to generate a random number from an array
- Generate a random string in Java
- Generate Random Integer Numbers in Java
- C++ program to generate random number
- Convert double primitive type to a Double object in Java
- Java program to generate random numbers
- How to generate a random number in C++?

Advertisements