Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a random number between 0 and 0.06 in Java?

Tags:

java

random

How do you get random Double values between 0.0 and 0.06 in Java?

like image 825
podunk Avatar asked Feb 09 '10 16:02

podunk


2 Answers

nextDouble() returns a random floating-point number uniformly distributed between 0 and 1. Simply scale the result as follows:

Random generator = new Random();
double number = generator.nextDouble() * .06;

See this documentation for more examples of Random.

like image 178
Dolph Avatar answered Oct 11 '22 18:10

Dolph


This will give you a random double in the interval [0,0.06):

double r = Math.random()*0.06;
like image 29
uckelman Avatar answered Oct 11 '22 17:10

uckelman