com.jbergin.util
Class Die

java.lang.Object
  extended by com.jbergin.util.Die

public class Die
extends java.lang.Object

Represents a single Die that you can "roll" to get a random int. Unlike a standard die, these can have any number of "faces", even if that would be a physical impossibility. The random numbers generated are approximately uniform.

Version:
1.0
Author:
Joseph Bergin

Constructor Summary
Die(int faces)
          Create a die with any number of faces.
 
Method Summary
 int faces()
          Learn the number of faces on this die.
static int mostRecent()
          Roll the most recently created die and return the result
 int roll()
          get a random number in the range [1..faces] inclusive.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Die

public Die(int faces)
Create a die with any number of faces.

Parameters:
faces - the number of faces on the die
Method Detail

mostRecent

public static final int mostRecent()
Roll the most recently created die and return the result

Returns:
the result of rolling the most recently created die, or 0 if none have been created

roll

public int roll()
get a random number in the range [1..faces] inclusive.


faces

public int faces()
Learn the number of faces on this die.