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:
@@ -57,7 +57,7 @@ public class RandomUtil
|
|||||||
*/
|
*/
|
||||||
public static int getInt (int high, Random r)
|
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;
|
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
|
* Pick a random index from the array, weighted by the value of the corresponding array
|
||||||
* element.
|
* element.
|
||||||
|
|||||||
Reference in New Issue
Block a user