This question already has an answer here:
I am currently working on a java project that requires me to generate a random percentage within a range values a high (stored in a variable called max) and a low (stored in a variable of min) I am fairly new to java and cannot figure out the errrors i am getting, when I am able to get the code to compile it generates a 0.0. Any help would be appreciated.
public static void runSimulation() {
Random randInvest = new Random();
randInvest = minSalRange + (float)(Math.random() * maxSalRange);
System.out.println("The random generated number was"+randInvest);
}
Here is the version I am able to run which kicks out 0.0 every time
public static void runSimulation() {
randInvest = minSalRange + (float)(Math.random() * maxSalRange);
System.out.println("The random generated number was"+randInvest);
}
Aucun commentaire:
Enregistrer un commentaire