01: import java.util.Random;
02: 
03: /**
04:    This class models a die that, when cast, lands on a random
05:    face.
06: */
07: public class Die
08: {
09:    /**
10:       Constructs a die with a given number of sides.
11:       @param s the number of sides, e.g. 6 for a normal die
12:    */
13:    public Die(int s)
14:    {
15:       sides = s;
16:       generator = new Random();
17:    }
18: 
19:    /**
20:       Simulates a throw of the die
21:       @return the face of the die 
22:    */
23:    public int cast()
24:    {
25:       return 1 + generator.nextInt(sides);
26:    }
27:    
28:    private Random generator;
29:    private int sides;
30: }