public int []  shuffle(int [] arr) {
      int [] arr2 =new int[arr.length];
      int count = arr.length;
      int cbRandCount = 0;// 索引
      int cbPosition = 0;// 位置
      int k =0;
      do {
       Random rand = new Random();
       int r = count - cbRandCount;
       cbPosition = rand.nextInt(r); 
       arr2[k++] = arr[cbPosition];
       cbRandCount++;
       arr[cbPosition] = arr[r - 1];// 将最后一位数值赋值给已经被使用的cbPosition
      } while (cbRandCount < count);
      return arr2;
     }

 

 posted on 2015-07-03 01:18  瀚海  阅读(542)  评论(0编辑  收藏  举报