diff --git a/src/java/com/samskivert/util/RandomUtil.java b/src/java/com/samskivert/util/RandomUtil.java index 608f7ee7..1fbe9b8b 100644 --- a/src/java/com/samskivert/util/RandomUtil.java +++ b/src/java/com/samskivert/util/RandomUtil.java @@ -63,14 +63,31 @@ public class RandomUtil /** * Returns a pseudorandom, uniformly distributed int value between * high and low, exclusive of each. + * + * @deprecated use getRange(int, int). */ + @Deprecated public static int getInt (int high, int low) { - if (high - low - 1 <= 0) { - throw new IllegalArgumentException( - "Invalid range [high=" + high + ", low=" + low + "]"); - } - return low + 1 + rand.nextInt(high - low - 1); + return getRange(low + 1, high); + } + + /** + * Returns a pseudorandom, uniformly distributed int value between + * low (inclusive) and high (exclusive). + */ + public static int getRange (int low, int high) + { + return low + rand.nextInt(high - low); + } + + /** + * Returns a pseudorandom, uniformly distributed float value between + * low (inclusive) and high (exclusive). + */ + public static float getRange (float low, float high) + { + return low + (rand.nextFloat() * (high - low)); } /**