1. shuffle算法:
http://www.cnblogs.com/huaping-audio/archive/2008/09/09/1287985.html
注意:我们一般用的是第二种swap的方法;但是第一种直接选择,然后把最末尾一位填上的方法,也是很好的。只是会需要两倍的空间。
2. Random nextInt(bound)参数表示 0-inclusive,bound-exclusive: [0, bound)
package com.company;import java.util.LinkedList;import java.util.List;import java.util.Random;public class Main { private int[] orig; public Main(int[] nums) { orig = nums; } /** Resets the array to its original configuration and return it. */ public int[] reset() { return orig; } /** Returns a random shuffling of the array. */ public int[] shuffle() { int[] ret = orig.clone(); Random rand = new Random(); for (int i=0; i