Hey guys.
I see far too many servers using this method to generate percentage chance;
Code:
int chance = 10;
if (Misc.random(100) <= chance){
doSomething;
}
I made these to simplify things:
Code:
public static double randomDouble(double i) {
return getRandomDouble(i);
}
public static boolean percentageChance(double percentage) {
return percentage >= randomDouble(100);
}
You need the random double method in order for for the percentage chance to work. Shove them into Misc.java or something.
Use like this (This example is generating a 10% chance)
Code:
if (Misc.percentageChance(10.0)) {
doSomething;
}
Let me know if there is anything wrong with the logic - it seems to work well, I tested a ton of calls using a for loop..
Thanks