• Register
1 vote
39 views

Problem:

Well, Java is a fun programming language to learn. I am adopting this language very quickly, I guess. I am wondering if I can generate a random double between 0 and 1 in java. Is it possible? Could you guys shed some light on this?
Many Thanks!

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

I think the question is already answered in this thread. Though the answered question was not exactly the same as yours’ but pretty similar. I am changing the answer a little bit from float to double as per your question demands.

import java.util.Random;
public class Test {
   public static void main(String[] args) {
      Random rand = new Random();
      System.out.println(rand.nextDouble());
   }
}

 

13 9 6
94,260 points

Related questions

1 vote
1 answer 6 views
6 views
Problem: Please help me to solve it out : java random double between 0 and 1
asked Mar 26 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 8 views
8 views
Problem: Why I got the error : java random number between 0 and 1
asked Mar 26 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 36 views
36 views
How can I get this?
asked Dec 19, 2020 TeamScript 13.5k points
0 votes
1 answer 9 views
9 views
Problem: Get random number between 0 and 1 in java In this post, we will see how to get random number between 0 to 1 in java. We have already seen random number generator in java. Math.random method returns double value between o(inclusive) to 1(exclusive).
asked Dec 3, 2020 Mashhoodch 13k points
0 votes
1 answer 8 views
8 views
Problem: How do I generate a double between the range of (example) -0.5 and 0.5 in java?
asked Apr 18 muktaa 34.6k points
1 vote
1 answer 4 views
4 views
Problem: How can I deal with this problem : java random number between 0 and 10
asked Mar 26 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 5 views
5 views
Problem: I need a help , How I can fix this : java random number between 0 and 100
asked Mar 26 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 7 views
7 views
Problem: I want to generate a number between 1 and 10 in Java. Here is what I tried: Random rn = new Random(); int answer = rn.nextInt(10) + 1; Is there a way to tell what to put in the parenthesis () when calling the nextInt method and what to add?
asked Apr 20 munim01 21k points
0 votes
1 answer 9 views
9 views
Question: I want to generate a number between 1 and 10 in Java. Here is what I tried: Random rn = new Random(); int answer = rn.nextInt(10) + 1; Is there a way to tell what to put in the parenthesis () when calling the nextInt method and what to add?
asked Apr 13 Atik03 26.5k points
0 votes
1 answer 9 views
9 views
Problem: Can anyone help me out from this? I am in trouble on this, please answer me.
asked Apr 1 niyatiry 3.9k points