diff --git a/src/java/com/samskivert/util/RandomUtil.java b/src/java/com/samskivert/util/RandomUtil.java index f755c464..8e98b934 100644 --- a/src/java/com/samskivert/util/RandomUtil.java +++ b/src/java/com/samskivert/util/RandomUtil.java @@ -57,7 +57,7 @@ public class RandomUtil */ public static int getInt (int high, Random r) { - return r.nextInt(high); + return r.nextInt(high); } /** @@ -95,6 +95,24 @@ public class RandomUtil return r.nextFloat() * high; } + /** + * Returns true approximately one in n times. + */ + public static boolean getChance (int n) + { + return getChance(n, rand); + } + + /** + * Returns true approximately one in n times. + * + * @param r the random number generator to use + */ + public static boolean getChance (int n, Random r) + { + return getInt(n, r) == 0; + } + /** * Pick a random index from the array, weighted by the value of the corresponding array * element.