I am looking to fill an array a with the numbers 1 through 10 and take a random number from that array and add it to an array b and remove that element from array a. I would like to know the most efficient way of doing this. EDIT: (The exercise requires that I not have repeated values in the arrays and that the permutation is random each time the method is called.) Here is my method so far:
public int[] nextPermutation() {
int capOne = 10;
int capTwo = 10;
int aSize = 0;
int bSize = 0;
int[] a = new int[capOne];
int[] b = new int[capTwo];
int upperBound = 11;
Random generator = new Random();
//fill initial array with 1 - 10
for (int i = aSize; i < 10; i++) {
a[i] = i + 1;
//companion variable for sizing array
aSize++;
}
//Create a random integer and add it to array b
//Remove same integer from array a
//Repeat and remove another random integer from the remaining integers in array a and add it to b
permuted = b;
return permuted;
}
I may be approaching this in an inefficient if not completely incorrect manner. If so, I'm sure you won't hesitate to tell me. Any help on this is greatly appreciated.