标签:
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; }
标签:
原文地址:http://www.cnblogs.com/xuhuaiqu/p/4617562.html