java随机发牌

import java.util.Random;
public class faPai {

public static void main(String[] args) {
   Random ran=new Random();
   int a[]=new int[54];
   int x[]=new int[18];
   int y[]=new int[18];
   int z[]=new int[18];
   int b=54;
   for(int i=0;i<54;i++){
    a[i]=i+1;
   }
   for(int i=0;i<18;i++){
    int r=ran.nextInt(b);
    x[i]=a[r];
    a[r]=a[b-1];
    b--;
    r=ran.nextInt(b);
    y[i]=a[r];
    a[r]=a[b-1];
    b--;
    r=ran.nextInt(b);
    z[i]=a[r];
    a[r]=a[b-1];
    b--;
   
   }
   System.out.print("小猪:");
   for(int i=0;i<18;i++){
    System.out.print(x[i]+" ");
   }System.out.println();
   System.out.print("小猫:");
   for(int i=0;i<18;i++){
    System.out.print(y[i]+" ");
   }System.out.println();
   System.out.print("小狗:");
   for(int i=0;i<18;i++){
    System.out.print(z[i]+" ");
   }System.out.println();
  
}

}

你可能感兴趣的:(java)