随机产生13个0~51不同的随机数 -思想(定义参考系)

  1. /*
  2.  * 随机产生13个0~51没有重复的随机数
  3.  * class : arrayok
  4.  *
  5.  */
  6.  public class arrayok
  7.  {
  8.      public static void main(String args[])
  9.      {
  10.          int suit[] = new int[13]; //存储13个随机数

  11.          boolean sw[] = new boolean[52]; //随机数存在。则为真,否则为假

  12.          int key = 0;
  13.          for(int i = 0; i < suit.length; i++)
  14.          {
  15.              while(true)
  16.              {
  17.                  key = (int)(Math.random()*52);
  18.                  if(sw[key] == false){
  19.                      break;
  20.                  }
  21.              }
  22.              suit[i] = key;
  23.              sw[key] = true;
  24.          }
  25.          for(int i = 0; i < suit.length; i++)
  26.          {
  27.              System.out.print(suit[i]+" ");
  28.          }
  29.          System.out.print(" ");
  30.      }
  31.  }
原文地址:https://www.cnblogs.com/archermeng/p/7537617.html