Skip to content

Instantly share code, notes, and snippets.

@rotespferd
Created October 17, 2009 11:38
Show Gist options
  • Save rotespferd/212324 to your computer and use it in GitHub Desktop.
Save rotespferd/212324 to your computer and use it in GitHub Desktop.
import java.util.Random;
public class Dice {
//Number of sides of the dice
private int sides;
//First number of the dice
private int firstNumber;
//Last number of the dice
private int lastNumber;
//Array of numbers of the dice
private int[] numbers;
private Random random;
/**
* @param sides
* @param firstNumber
* @param lastNumber
*/
public Dice(int sides, int firstNumber, int lastNumber) {
super();
this.sides = sides;
this.firstNumber = firstNumber;
this.lastNumber = lastNumber;
this.random = new Random();
}
public void init() {
this.numbers = new int[this.sides];
for (int i = 0; i < numbers.length; i++) {
this.numbers[i] = i + this.firstNumber;
}
}
public int rollDice() {
int out;
out = random.nextInt(lastNumber) + 1;
return out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment