私はCarオブジェクトのArrayListを持っています。それらのうちの2つをランダムに選択して比較したいと思います。私たちがそれらを比較すると、私は下位の車を無作為に選んで「取り除く」ことを望む。特定の数字が生成されるのを止めることはできないと思うので、私は他の考えを考えました。2つのランダムな整数を生成し、それらが再び生成されないようにします。
は、ここで私が考えてきたいくつかのものです:
Idea 1:
Include a "seen" attribute for each Car, set to false.
Generate two random integers from 0 to size of Car List.
Check to make sure two indexes are not seen.
Check to make sure that two integers are not the same, if they are, regenerate and repeat.
Grab cars using the two indexes generated.
If not seen, compare and flag the inferior as seen.
If seen, store that cars index in a seenIndex array.
Idea 2:
Create a copy (would a deep copy be required here, im thinking no?) of the list of Cars.
Generate two random numbers, confirm they're not the same.
Compare cars, remove the inferior car from the copyList.
Repeat.
は、私がアイデア2に傾いていますが、私は1つが存在する場合は、よりエレガントな解決策を聞いてみたいです。