📌  相关文章
📜  javascript 非重复随机化数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:12.188000             🧑  作者: Mango

代码示例1
var nums = [1,2,3,4,5,6,7,8,9,10],//all numbers to be randomized
    ranNums = [],
    i = nums.length,
    j = 0;

while (i--) {
    j = Math.floor(Math.random() * (i+1));
    ranNums.push(nums[j]);
    nums.splice(j,1);
}
ranNums.next().value; //To use afterwards (for each time that the numbers are used)