megamek.common
Class MMRandom

java.lang.Object
  extended by megamek.common.MMRandom
Direct Known Subclasses:
MMRandom.CryptoRandom, MMRandom.SunRandom

public abstract class MMRandom
extends java.lang.Object

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.

Author:
Ben

Nested Class Summary
(package private) static class MMRandom.CryptoRandom
          Uses java.security.SecureRandom
(package private) static class MMRandom.Pool36Random
          Behaves like SunRandom for everything but d6(2) calls.
(package private) static class MMRandom.SunRandom
          Uses com.sun.java.util.collections.Random
 
Field Summary
static int R_CRYPTO
           
static int R_DEFAULT
           
static int R_POOL36
           
static int R_SUN
           
 
Constructor Summary
MMRandom()
           
 
Method Summary
(package private)  Roll d6()
          A single die
(package private)  Roll d6(int nDice)
          Simulates six-sided die rolls.
(package private) static MMRandom generate(int type)
          Gives you the type asked for, defaulting to SunRandom if there are any errors.
(package private) abstract  int randomInt(int maxValue)
          Returns a random int in the range from 0 to one less than the supplied max value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

R_DEFAULT

public static final int R_DEFAULT
See Also:
Constant Field Values

R_SUN

public static final int R_SUN
See Also:
Constant Field Values

R_CRYPTO

public static final int R_CRYPTO
See Also:
Constant Field Values

R_POOL36

public static final int R_POOL36
See Also:
Constant Field Values
Constructor Detail

MMRandom

public MMRandom()
Method Detail

generate

static MMRandom generate(int type)
Gives you the type asked for, defaulting to SunRandom if there are any errors.


d6

Roll d6(int nDice)
Simulates six-sided die rolls.

Parameters:
nDice - - the int number of dice to roll. If this value is less than or equal to zero, an IllegalArgumentException will be thrown.
Returns:
a Roll object containing the roll results.
Throws:
IllegalArgumentException - will be thrown if the input is <= 0.

d6

Roll d6()
A single die


randomInt

abstract int randomInt(int maxValue)
Returns a random int in the range from 0 to one less than the supplied max value.

Parameters:
maxValue - - the smallest int value which will exceed any random number returned by this method.
Returns:
a random int from the value set [0, maxValue).