当前位置: 代码迷 >> 综合 >> js方法随机抽取n个随机数
  详细解决方案

js方法随机抽取n个随机数

热度:9   发布时间:2024-01-30 09:20:54.0
function getImageRandomPosition(){do {var n = Math.floor(Math.random() * 12);//n为随机出现的0-11之内的数值for (var i = 0; i < posArray.length; i++) {if (n == posArray[i]) { /*若n和数组里面的数值有重复,立即跳出函数*/break;}}/*若n和数组里的数组无重复,那么i和数组的长度是相同的,这样可以避免出现重复的数字*/if (i == posArray.length) {posArray.push(n);}}while(posArray.length!=12); }

 

  相关解决方案