Posted October 14, 20213 yr comment_63566 Hey guys. I see far too many servers using this method to generate percentage chance; int chance = 10; if (Misc.random(100) <= chance){ doSomething; } I made this one to simplify things: 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) if (Misc.percentageChance(10.0)) { doSomething; } Noice
Create an account or sign in to comment