乱数を生成したいが、それらをexcludeRows
配列にしたくない。ここに私のコードです。特定の値以外の乱数を生成する
public int generateRandom(int start, int end, ArrayList<Integer> excludeRows) {
Random rand = new Random();
int range = end - start +1 - excludeRows.size();
int random = rand.nextInt(range) + 1;
for(int i = 0; i < exclude.size(); i++) {
if(excludeRows.get(i) > random) {
return random;
}
random++;
}
return random;
}
私はwhileループでは、この機能を使用し、各反復の間に、私はexcludeRows
に新しい値を追加します。 時々、excludeRows
に属する番号を返します。どうしたの?
「excludeRows」と「exclude」は同じものですか? – Vlad
はい、名前を変更するのを忘れました – user2081119
この関数では、 'excludeRows'に数値を追加しません。それで私の解決策では、私はそれをやっていません。私はそれを補足する必要がありますか? – qben