My code so far is working almost to how it should be working. The instructions are above the method. The only problem that I'm encountering is that Math.random();
repeats itself when called multiple times. I wanted to know if there was a solution to prevent the Math.random();
from repeating itself;
/**
* Apply an "efficient selection shuffle" to the argument.
* The selection shuffle algorithm conceptually maintains two sequences
* of cards: the selected cards (initially empty) and the not-yet-selected
* cards (initially the entire deck). It repeatedly does the following until
* all cards have been selected: randomly remove a card from those not yet
* selected and add it to the selected cards.
* An efficient version of this algorithm makes use of arrays to avoid
* searching for an as-yet-unselected card.
* @param values is an array of integers simulating cards to be shuffled.
*/
public static void selectionShuffle(int[] values) {
ArrayList<Integer> temp=new ArrayList<Integer>();
int size=52;
for(int j=0;j<size;j++){
/*int random=(int)(Math.random()*51);
temp.add(random);
values[j]=temp.get(j);*/
int random=(int)(Math.random()*51);
temp.add(values[random]);
values[j]=temp.get(j);
}
}