org.mars_sim.msp.simulation
Class RandomUtil

java.lang.Object
  extended by org.mars_sim.msp.simulation.RandomUtil

public final class RandomUtil
extends java.lang.Object

The RandomUtil class is a library of various random-related methods


Constructor Summary
RandomUtil()
           
 
Method Summary
static double getRandomDouble(double ceiling)
          Returns a random double number from 0 to the ceiling number given.
static int getRandomInt(int ceiling)
          Returns a random int number from 0 to (and including) the number given.
static int getRandomInt(int base, int ceiling)
          Returns a random int number from a given base number to (and including) the ceiling number given.
static int getRandomRegressionInteger(int ceiling)
          Returns a random integer from 1 to the given integer.
static double getRandomRegressionIntegerAverageValue(int ceiling)
          Gets the average value returned from the getRandomRegressionInteger method.
static java.lang.Object getWeightedRandomObject(java.util.Map weightedMap)
          Gets a random weighted object from a map.
static boolean lessThanRandPercent(double randomLimit)
          Returns true if given number is less than a random percentage.
static boolean lessThanRandPercent(int randomLimit)
          Returns true if given number is less than a random percentage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomUtil

public RandomUtil()
Method Detail

lessThanRandPercent

public static boolean lessThanRandPercent(int randomLimit)
Returns true if given number is less than a random percentage.

Parameters:
randomLimit - the random percentage limit
Returns:
true if random percent is less than percentage limit

lessThanRandPercent

public static boolean lessThanRandPercent(double randomLimit)
Returns true if given number is less than a random percentage.

Parameters:
randomLimit - the random percentage limit
Returns:
true if random percent is less than percentage limit

getRandomInt

public static int getRandomInt(int ceiling)
Returns a random int number from 0 to (and including) the number given.

Parameters:
ceiling - the int limit for the random number
Returns:
the random number

getRandomInt

public static int getRandomInt(int base,
                               int ceiling)
Returns a random int number from a given base number to (and including) the ceiling number given.

Parameters:
base - the minimum number result
ceiling - the maximum number result
Returns:
the random number

getRandomDouble

public static double getRandomDouble(double ceiling)
Returns a random double number from 0 to the ceiling number given.

Parameters:
ceiling - the maximum number result
Returns:
the random number

getRandomRegressionInteger

public static int getRandomRegressionInteger(int ceiling)
Returns a random integer from 1 to the given integer. -breakiterator 1 has twice the chance of being chosen as 2 and so forth to the given integer.

Parameters:
ceiling - the maximum integer result, ( ceiling > 0 )
Returns:
the random integer

getRandomRegressionIntegerAverageValue

public static double getRandomRegressionIntegerAverageValue(int ceiling)
Gets the average value returned from the getRandomRegressionInteger method.

Parameters:
ceiling - the maximum integer result, (ceiling > 0)
Returns:
average value.

getWeightedRandomObject

public static java.lang.Object getWeightedRandomObject(java.util.Map weightedMap)
Gets a random weighted object from a map.

Parameters:
weightedMap - a map of objects and their weights as Double values.
Returns:
randomly selected object from the list (or null if empty map).