配列内のランダムな数字を選び、次回同じ数字を選ばないようにする関数を作りたいです。
これが私のコードです(それはいつか、そしてほとんどの場合infループで動作します)
助けてください、ありがとう。
private static int pick(int[] x) {
int upperbound = x[x.length-1];
int lowerbound = x[0];
int count=0;
int ranvalue;
int ranindex;
Random rand = new Random();
do{
ranindex = rand.nextInt(upperbound-lowerbound) + lowerbound;
count++;
}while(x[ranindex]==-1||count!=x.length-1);
ranvalue=x[ranindex];
x[ranindex]=-1;
return ranvalue;
}