配列 a に 1 ~ 10 の数字を入力し、その配列から乱数を取得して配列 b に追加し、配列 a からその要素を削除しようとしています。これを行う最も効率的な方法を知りたいです。EDIT:(この演習では、配列に値が繰り返されておらず、メソッドが呼び出されるたびに順列がランダムである必要があります。)これまでの私の方法は次のとおりです。
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;
}
完全に間違った方法ではないにしても、私はこれに非効率的にアプローチしている可能性があります。もしそうなら、私はあなたが私に言うことを躊躇しないと確信しています. これに関するヘルプは大歓迎です。