public void shuffle(int[] nums) {
int n = nums.length;
Random random = new Random();
for (int i = 0; i < n; i++) {
int r = i + random.nextInt(n-i);
//System.out.println(i + " , " + r);
exch(nums, i, r);
}
System.out.println();
}
private void exch(int[] nums, int i, int j) {
int tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
乱序 洗牌 打乱顺序 随机
最新推荐文章于 2021-03-15 16:59:13 发布