import java.util.concurrent.ThreadLocalRandom;

/**
 * A collection of dice that can be rolled individually or all at once. 
 *
 * @author Drue Coles
 */
public class CupOfDice {
    
    private final int[] dice;
    private final int sides;
    
    /**
     * Creates a cup of dice with random initial values. 
     */
    public CupOfDice(int numDice, int sides) {
        this.dice = new int[numDice];
        this.sides = sides;
        roll();
    }
        
    /**
     * Creates a cup of 6-sided dice with random initial values.
     */
    public CupOfDice(int numDice) {
        this(numDice, 6);
    }
    
    /**
     * Rolls each die in the cup. 
     * 
     * @return the current dice values
     */
    public final int[] roll() { 
        for (int i = 0; i < dice.length; i++) {
            roll(i);
        }
        return dice.clone();
    }  
    
    /**
     * Rolls a specified die.
     * 
     * @return a copy of the current dice values
     */
    public final int[] roll(int i) {    
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        dice[i] = rand.nextInt(1, sides + 1);        
        return dice.clone();
    }
}