blob: dc512b40b7c2d10f9d51fa9640c787e1ad58469a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package bjc.utils.dice;
import java.util.Random;
/**
* A single polyhedral dice
* @author ben
*
*/
public class Die implements IDiceExpression {
/**
* Random # gen to use for dice
*/
private static Random rng = new Random();
/**
* Number of sides this die has
*/
private int nSides;
/**
* Create a die with the specified number of sides
* @param nSides The number of sides this dice has
*/
public Die(int nSides) {
this.nSides = nSides;
}
/**
* Roll this dice once
* @return The result of rolling the dice
*/
public int roll() {
return rng.nextInt(nSides + 1);
}
}
|