hi there guys.. i am given a task about java.util.Random...
i need to come up with an array with unique int values...
like, 1 can only appear once, 2 must appear once, so on and so forth...
i mean, no same value within the array...
So, you need an array of random, but unique integers?
One way you could do this is by making a loop for all the elements of the array, and in each iteration generate a random number, check if it is already in the array, and if it is not, then put it in the array and go to the next iteration; otherwise, generate another random number (until you get one that's not already in the array). This approach has a major disadvantage: in principle it could run forever, or it could take a long time before the random number generator creates a number that's not already in the array. It will probably work OK if the size of the array is small compared to the range of random integers that you're choosing from.
Another way is to fill a list with numbers (just 1, 2, 3, ..., etc.) and then shuffle the list using Collections.shuffle();.
I would include a comment that this is the shuffling algorithm as used by Collections.sort. It is available from the src.zip file that comes with the JDK installatation, and it informs your professor that you know to look for methods in the API first. After all, you need to understand your own solution. If you don't get the shuffling then use your old code (but with ArrayList).