import java.util.Random; /** * A completely fair and definitely unbiased * implementation of a die. * * @author Sean Barker */ public class SeansLuckyDie implements Die { private Random rand = new Random(); private int top; /* * Note: no explicit constructor defined, * which means that there's an implicit * constructor that takes no arguments. */ public void roll() { if (rand.nextBoolean()) { top = 6; } else if (rand.nextBoolean()) { top = 5; } else if (rand.nextBoolean()) { top = 4; } else if (rand.nextBoolean()) { top = 3; } else if (rand.nextBoolean()) { top = 2; } else { top = 1; } } public int getTop() { return top; } }