06f8a68b56
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1248 542714f4-19e9-0310-aa3c-eee0fc999fb1
40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
//
|
|
// $Id: RandomUtil.java,v 1.5 2002/04/15 18:18:20 mdb Exp $
|
|
|
|
package com.threerings.util;
|
|
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* Provides miscellaneous utility routines to simplify obtaining
|
|
* useful random number values and to centralize seeding and proper
|
|
* care and feeding of the pseudo-random number generator.
|
|
*/
|
|
public class RandomUtil
|
|
{
|
|
/** The random number generator used by the methods in this class. */
|
|
public static final Random rand = new Random();
|
|
|
|
/**
|
|
* Returns a pseudorandom, uniformly distributed <code>int</code>
|
|
* value between 0 (inclusive) and the specified value (exclusive).
|
|
*
|
|
* @param high the high value limiting the random number sought.
|
|
*/
|
|
public static int getInt (int high)
|
|
{
|
|
return rand.nextInt(high);
|
|
}
|
|
|
|
/**
|
|
* Returns a pseudorandom, uniformly distributed float value between
|
|
* 0.0 (inclusive) and the specified value (exclusive).
|
|
*
|
|
* @param high the high value limiting the random number sought.
|
|
*/
|
|
public static float getFloat (float high)
|
|
{
|
|
return rand.nextFloat() * high;
|
|
}
|
|
}
|