The following code shuffles playing cards in a game. I have to explain what the code does in a presentation. I am a newbie in Java coding, so can anyone please explain to me the following code line by line:
// Deck shuffling method
public void shuffleDeck() {
//Seed the Random instance with nanoTime
Random random = new Random(System.nanoTime());
for(int i = 0; i < 52; i++) {
int swapIndex = random.nextInt(52);
if (swapIndex != i) {
PlayingCard temp = cardDeckArray[i];
cardDeckArray[i] = cardDeckArray[swapIndex];
cardDeckArray[swapIndex] = temp;
}
}
cardIndex = 0; //Next card to be pulled off the deck
}