diff --git a/src/java/com/samskivert/util/RandomUtil.java b/src/java/com/samskivert/util/RandomUtil.java index 8e98b934..a3715a30 100644 --- a/src/java/com/samskivert/util/RandomUtil.java +++ b/src/java/com/samskivert/util/RandomUtil.java @@ -67,7 +67,8 @@ public class RandomUtil public static int getInt (int high, int low) { if (high - low - 1 <= 0) { - throw new IllegalArgumentException("Invalid range [high=" + high + ", low=" + low + "]"); + throw new IllegalArgumentException( + "Invalid range [high=" + high + ", low=" + low + "]"); } return low + 1 + rand.nextInt(high - low - 1); } @@ -113,6 +114,24 @@ public class RandomUtil return getInt(n, r) == 0; } + /** + * Returns a pseudorandom, uniformly distributed boolean. + */ + public static boolean getBoolean () + { + return getBoolean(rand); + } + + /** + * Returns a pseudorandom, uniformly distributed boolean. + * + * @param r the random number generator to use + */ + public static boolean getBoolean (Random r) + { + return r.nextBoolean(); + } + /** * Pick a random index from the array, weighted by the value of the corresponding array * element.