# Very simple question (nextDouble- Random class)

• October 24th, 2013, 06:08 PM
TSSF44
Very simple question (nextDouble- Random class)
*
If I change the method to nextInt, it works fine though. How can I use nextDouble without getting the error message? Method next.Double cannot be applied. Required : no arguments, Found: int. Keep in mind, I need the values of the randoms to be in the range 10-20.

Code :

```  import java.util.Random;     class Randoms { public static void main (String[] args) { Random r = new Random();     for (int x = 0; x < 10000; x++) {   double random = r.nextDouble(10) + 10; // This line is not working. * System.out.println(random); } }   }```
• October 24th, 2013, 06:32 PM
GoodbyeWorld
Re: Very simple question (nextDouble- Random class)
There is no param to nextDouble(). It returns a number between 0.0 and 1.0.

One way of getting it to do it with 10 is to multiply the result of nextDouble by 10 and put it in a double variable.
• October 24th, 2013, 06:38 PM
TSSF44
Re: Very simple question (nextDouble- Random class)
Quote:

Originally Posted by GoodbyeWorld
There is no param to nextDouble(). It returns a number between 0.0 and 1.0.

One way of getting it to do it with 10 is to multiply the result of nextDouble by 10 and put it in a double variable.

Thank you. That's what I thought. My professor insists that I use nextDouble. By doing what you said, I can get the range from 10 to 20? It seems to be 0 - 10.
• October 25th, 2013, 04:49 AM
GregBrannon
Re: Very simple question (nextDouble- Random class)
Then add 10 to that result. C'mon, think!
• October 27th, 2013, 10:07 PM
TSSF44
Re: Very simple question (nextDouble- Random class)
Quote:

Originally Posted by GregBrannon
Then add 10 to that result. C'mon, think!

Thanks, I figured it out after posting that. I shouldn't be so quick to ask questions.