import java.util.Arrays;
public class CardShuffling {
public CardShuffling() {
}
public static void main(String[] args) {
CardShuffling cardShuffling = new CardShuffling();
int[] cards = new int[52];
for (int i = 0; i <cards.length ; i++)cards[i]=i;
System.out.println("Initial stetae of the deck");
System.out.println(Arrays.toString(cards));
knuthShuffle(cards);
System.out.println("After shuffling");
System.out.println(Arrays.toString(cards));
}
/** Generates a random permutation of the array using Knuth's shuffle algorithm */
public static void knuthShuffle(int[] a) {
for (int i = 0; i < a.length; i++) {
// Pick a random index in i ... a.length-1
int k = i + (int) (Math.random() * (a.length - i));
// Swap.
int temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
}