Package megamek.common
Class MMRandom
java.lang.Object
megamek.common.MMRandom
Used by Compute to generate random numbers, usually dice rolls. The base class is abstract, having a number of
concrete subclasses that it will give using the generate() method.
- Since:
- April 27, 2003, 11:29 PM
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiond6()A single died6(int nDice) Simulates six-sided die rolls.d6(int nDice, int keep) static MMRandomgenerate(int type) Gives you the type asked for, defaulting to SunRandom if there are any errors.abstract floatReturns a randomfloatin the range of 0 to 1abstract intrandomInt(int maxValue) Returns a randomintin the range from 0 to one less than the supplied max value.
-
Field Details
-
R_DEFAULT
public static final int R_DEFAULT- See Also:
-
R_SUN
public static final int R_SUN- See Also:
-
R_CRYPTO
public static final int R_CRYPTO- See Also:
-
R_POOL36
public static final int R_POOL36- See Also:
-
-
Constructor Details
-
MMRandom
public MMRandom()
-
-
Method Details
-
generate
Gives you the type asked for, defaulting to SunRandom if there are any errors. -
d6
Simulates six-sided die rolls.- Parameters:
nDice- - theintnumber of dice to roll. If this value is less than or equal to zero, anIllegalArgumentExceptionwill be thrown.- Returns:
- a
Rollobject containing the roll results. - Throws:
IllegalArgumentException- will be thrown if the input is <= 0.
-
d6
-
d6
A single die -
randomInt
public abstract int randomInt(int maxValue) Returns a randomintin the range from 0 to one less than the supplied max value.- Parameters:
maxValue- - the smallestintvalue which will exceed any random number returned by this method.- Returns:
- a random
intfrom the value set [0, maxValue).
-
randomFloat
public abstract float randomFloat()Returns a randomfloatin the range of 0 to 1- Returns:
- a random
floatfrom the value set [0, 1]
-