New convenience functions from Dave. What are the chances?

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2456 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2008-10-22 00:55:40 +00:00
parent 39c9f7a499
commit 8ac0e012ce
+19 -1
View File
@@ -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.