Added getProbability(), from Dave Hoover.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2698 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray.j.greenwell
2010-01-13 18:34:15 +00:00
parent eecca9d71b
commit 05d562387c
@@ -114,6 +114,24 @@ public class RandomUtil
return getInt(n, r) == 0;
}
/**
* Has a probability p of returning true.
*/
public static boolean getProbability (float p)
{
return getProbability(p, rand);
}
/**
* Has a probability p of returning true.
*
* @param r the random number generator to use
*/
public static boolean getProbability (float p, Random r)
{
return r.nextFloat() < p;
}
/**
* Returns a pseudorandom, uniformly distributed boolean.
*/