public static void main(String[] args) {
int times = 99999;
int random1To20 = 0;
int random20To100 = 0;
for (int i = 0; i
double random = getRandom();
System.out.println(random);
if (random > 0.2) {
random20To100++;
} else {
random1To20++;
}
}
System.out.println("0.01~0.2概率:" + random1To20 / (double) times);
System.out.println("0.2~1概率:" + random20To100 / (double) times);
}
private static double getRandom() {
double r1 = getRandom(1, 20) / 100.0;
double r2 = getRandom(20, 100) / 100.0;
float r3 = getRandom(0, 100);
return r3
}
private static long getRandom(int min, int max) {
return Math.round(Math.random() * (max - min) + min);
}