import java.util.Random;
public class CreateCard {
public static void main(String[] args) {
int[] cards = createAllCard();
altoCard(cards);
for (int num : cards) {
System.out.println(num);
}
}
/*
private static int[] createAllCard() {
int[] cards = new int[54];
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 13; j++) {
cards[13 * (i - 1) + j - 1] = i * 100 + j;
}
}
cards[52] = 998;
cards[53] = 999;
return cards;
}
// 模拟洗牌
private static void altoCard(int[] cards) {
Random random = new Random();
int temp;
for (int i = 53; i > 0; i--) {
int altoIndex = random.nextInt(i + 1);
if (altoIndex != i) {
temp = cards[i];
cards[i] = cards[altoIndex];
cards[altoIndex] = temp;
}
// 这是洗牌的另一种实现
// int altoIndex = random.nextInt(i);
// temp = cards[i];
// cards[i] = cards[altoIndex];
// cards[altoIndex] = temp;
}
}
}
public class CreateCard {
public static void main(String[] args) {
int[] cards = createAllCard();
altoCard(cards);
for (int num : cards) {
System.out.println(num);
}
}
/*
* 生成一副牌,共54张 红桃,黑桃,方块,梅花分别用1,2,3,4表示
* A,2,...,10,J,Q,K分别用1-13表示 小王-998,大王999
*/private static int[] createAllCard() {
int[] cards = new int[54];
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 13; j++) {
cards[13 * (i - 1) + j - 1] = i * 100 + j;
}
}
cards[52] = 998;
cards[53] = 999;
return cards;
}
// 模拟洗牌
private static void altoCard(int[] cards) {
Random random = new Random();
int temp;
for (int i = 53; i > 0; i--) {
int altoIndex = random.nextInt(i + 1);
if (altoIndex != i) {
temp = cards[i];
cards[i] = cards[altoIndex];
cards[altoIndex] = temp;
}
// 这是洗牌的另一种实现
// int altoIndex = random.nextInt(i);
// temp = cards[i];
// cards[i] = cards[altoIndex];
// cards[altoIndex] = temp;
}
}
}