/*
* SuffleDemo.java
* Created March 29, 2004
* Created by Alice Armstrong
*
* This executable class randomly orders the numbers 0 through SIZE,
* where SIZE is a constant >= 0.
*
* SIZE is initially set to 10
*
*/
import java.util.Random;

public class SuffleDemo
{

  public static void main(String[] args)
  {
    final int SIZE = 10;                    //maximum size of the arrays
    boolean[] usedNums = new boolean[SIZE]; //keeps track of the numbers that have been used
    int[] outArray = new int[SIZE];         //stored the numbers in their randomized order
    int numFilled = 0;                      //keeps track of the number of elements filled in outArray
    int randChoice;                         //a random number
    Random gen = new Random();              //a random number generator

    for (int i=0; i < usedNums.length; i++)
    {
      //we haved used any of the numbers yet
      usedNums[i] = false;

      //all slots in outArray are initialized to a value
      //which is clearly out of range
      outArray[i] = -1;
    }

    //as long as we need to fill a slot in outArray
    while (numFilled < SIZE )
    {
      //get a random index
      randChoice = gen.nextInt(SIZE);

      //if we have not used randChoice all ready
      if (!usedNums[randChoice])
      {
        //mark index #randChoice as used
        usedNums[randChoice] = true;

        //assign the next spot in outArray
        //to the randomly selected number
        outArray[numFilled] = randChoice;

        //incremented the number of spots filled in outArray
        numFilled++;
      }
    }

    //print out the randomized list of numbers
    System.out.println("A randomized list of the numbers from 0 to "+(SIZE-1));

    for (int i=0; i< outArray.length; i++)
    {
      System.out.print(""+outArray[i]+" ");
    }
  }
}