How to generate numbers from an array randomly,with each number being unique
<p>I hav a numeric array,which contains 20 elements.I am displaying the numbers randomly for a blackberry application,bt i want dat all d numbers generated should b unique.It should b randomly generated,bt it has b unique until all the elemnts in the array is exhausted.I am giving the piece of code here,if anyone can help me out,i will b extremely grateful.</p>

<pre><code>static int quesNum[] = new int[20];
static int quesCount = -1;

private static void initialize(){

    Random rgen = new Random();  // Random number generator

    //--- Initialize the array 
    for (int i=0; i&lt;quesNum.length; i++) {
        quesNum[i] = i;
    }

    //--- Shuffle by exchanging each element randomly
    for (int i=0; i&lt; quesNum.length; i++) {
        int randomPosition = rgen.nextInt(quesNum.length);

        int temp = quesNum[i];

        quesNum[i] = quesNum[randomPosition];

        quesNum[randomPosition] = temp;

    }
}

/*Changed the code to get a unique random number

*/
public static int getQuestionNumber() {
    quesCount++;
    if(quesCount &lt; quesNum.length){
        return quesNum[quesCount];
     }
    else{ 
       initialize();
       quesCount = -1;
       return getQuestionNumber();
    }
}
</code></pre>
