Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to generate a random double number between min and max in Java

2 Answers

0 votes
public class GenerateRandomDoubleNumber_Java {
    public static double GenerateRandomDoubleNumberMinMax(double min, double max) {
        return Math.random() * (max - min + 1) + min; 
    }
    public static void main(String args[]) {
        double min = 70;
        double max = 100;
  
        double d = GenerateRandomDoubleNumberMinMax(min, max);
          
        System.out.println(d);
    }
}
  
  
  
/*
run:
  
85.60353458328242
  
*/

 



answered Feb 28, 2021 by avibootz
edited Jul 21, 2024 by avibootz
0 votes
import java.util.Random;

public class GenerateRandomDoubleNumber_Java {
    public static double GenerateRandomDoubleNumberMinMax(double  min, double max) {
        Random r = new Random();
        
        return r.nextDouble() * (max - min + 1) + min; 
    }
    public static void main(String args[]) {
        double  min = 70;
        double  max = 100;
 
        double d = GenerateRandomDoubleNumberMinMax(min, max);
         
        System.out.println(d);
    }
}
 
 
 
/*
run:
 
98.11906499490257
 
*/

 



answered Jul 21, 2024 by avibootz

Related questions

1 answer 130 views
1 answer 114 views
1 answer 105 views
1 answer 109 views
...