Q:

How to get different random numbers?

Possible Duplicate:
Non repeating random number array 

I have a String array with many elements (as I haven't still finished the Application, I don't know exactly the number), maybe about 200. I would like to get 20 random elements of this array, but being certain that every random element occurs only once, like, I don't want to get in those 20 elements the 5th element (for example) twice. How can I do this?

A:

I assume it's Java.
If that's right you could do something like:
public void getRandomElementsOfArray(String[] array)
{
    int maxLength = 200; // Insert length of your array
    int[] usedRandoms;
    String[] randomElements = String[20];
    int random = new Random().nextInt();

    for(int i = 0; i<21; i++) // Loops are NOT my strongest point. you'd better check this
    {
        while(random > maxLength || random < 0 || !Arrays.asList(usedRandoms).contains(random)) // Loop while random is smaller then 0 (the smallest index) or bigger then the length of your array or already used
        {
            random = new Random();
        }

        randomElements[i] = array[random];
        usedRandoms[i] = random;
    }
}

