function rand(arr) { var len = arr.length //首先从最大的数开始遍历,之后递减 for(var i = arr.length - 1; i >= 0; i--) { //随机索引值randomIndex是从0-arr.length中随机抽取的 var randomIndex = Math.floor(Math.random() * (i + 1)); //下面三句相当于把从数组中随机抽取到的值与当前遍历的值互换位置 var itemIndex = arr
Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums); // Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must equally lik