mardi 31 mars 2020

How to generate a random double number in Java? (not necessarily in the range [0,1]) [duplicate]

I want to generate a random double number. My approach -

Random random = new Random();
double myDouble = random.nextLong() + random.nextDouble();

But The result is always a number between -9.99999.... to + 9.99999....

How to get a double number in the entire legal double range?

The question "Java: Generating a random double between the range of a negative double and a positive double"

does not solve my problem as it has lower and upper bound, but I want a result in the entire legal double range




Aucun commentaire:

Enregistrer un commentaire