import java.util.Random;

public class Die
{
  private static Random generator = new Random();
  
  private int numberOfSides;
  
  public Die()
  {
    numberOfSides = 6;
  }
  
  public Die( int sides )
  {
    numberOfSides = sides;
  }
  
  public int roll()
  {
    int randomValue = generator.nextInt( numberOfSides );
    return randomValue + 1;
  }
  
  // ----- methods for Session 22 ---------------------------------------------
  
  public void uniqueRollsV1()
  {
    int rollOne = this.roll();
    int rollTwo = this.roll();
    while ( rollTwo == rollOne )
      rollTwo = this.roll();
    System.out.println( "Rolls: " + rollOne + " " + rollTwo );
  }
  
  public int[] uniqueRolls( int count )
  {
    int[] result = new int[count];
    
    for ( int i = 0; i < count; i++ )
    {
      int roll = this.roll();
      while ( isRepeat(roll, result, i) )
        roll = this.roll();
      result[i] = roll;
    }
    
    return result;
  }
  
  private boolean isRepeat( int roll, int[] previousRolls, int count )
  {
    for ( int i = 0; i < count; i++ )
    {
      if ( roll == previousRolls[i] )
        return true;
    }
    
    return false;
  }
  
  // ----- main method to test unique rolls, using Powerball example ----------
  
  public static void main( String[] args )
  {
    Die d1 = new Die( 55 );
    Die d2 = new Die( 42 );
    
    int[] fiveBalls = d1.uniqueRolls( 5 );
    int   powerBall = d2.roll();
    
    for (int i = 0; i < fiveBalls.length; i++)
      System.out.print( " " + fiveBalls[i] );
    System.out.println( " ... " + powerBall );
  }
}