Flub 1,279 Posted October 14, 2021 Report Share Posted October 14, 2021 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 1 Link to comment Share on other sites More sharing options...
remilol 1 Posted November 7, 2021 Report Share Posted November 7, 2021 Nice and simple Link to comment Share on other sites More sharing options...
kishen17 0 Posted November 13, 2021 Report Share Posted November 13, 2021 ty Link to comment Share on other sites More sharing options...
TestySauce 1 Posted December 2, 2021 Report Share Posted December 2, 2021 very useful thanks brother Link to comment Share on other sites More sharing options...
ExoticDX 0 Posted January 24, 2022 Report Share Posted January 24, 2022 thank u for dis boolean Link to comment Share on other sites More sharing options...
superb 0 Posted January 31, 2022 Report Share Posted January 31, 2022 yes yes good! Link to comment Share on other sites More sharing options...
shadowisdom 1 Posted February 6, 2022 Report Share Posted February 6, 2022 thanks for this Link to comment Share on other sites More sharing options...
0117be 66 Posted June 2, 2022 Report Share Posted June 2, 2022 Very sick! Link to comment Share on other sites More sharing options...
mire 0 Posted October 29, 2022 Report Share Posted October 29, 2022 Extremely simple and easy and makes the code look nicer. +1 Link to comment Share on other sites More sharing options...
nsin25 0 Posted February 7, 2023 Report Share Posted February 7, 2023 Thanks Flub! Link to comment Share on other sites More sharing options...
Fat nerd 0 Posted July 13, 2023 Report Share Posted July 13, 2023 Thanks for this Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now