diff --git a/src/resources/common/MathUtilities.java b/src/resources/common/MathUtilities.java index 8decf30b..b6159ac0 100644 --- a/src/resources/common/MathUtilities.java +++ b/src/resources/common/MathUtilities.java @@ -22,6 +22,7 @@ package resources.common; import java.math.BigDecimal; +import java.util.Random; import engine.resources.scene.*; @@ -68,4 +69,25 @@ public class MathUtilities { BigDecimal dec = new BigDecimal(seconds); return dec.remainder(new BigDecimal(3600)).divide(new BigDecimal(60), BigDecimal.ROUND_FLOOR).intValue(); } + + public static boolean tryChance(int chance) { + if (chance <= 0) { + return false; + } + + if (chance >= 100) { + return true; + } + + chance = (100 - chance); + + Random random = new Random(); + + if (random.nextInt(chance + 1) == 1) { + return true; + } + + return false; + } + }