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);
}

 

相关文章:

  • 2021-09-19
  • 2021-12-24
  • 2021-09-19
  • 2021-09-19
  • 2021-12-24
  • 2021-09-19
猜你喜欢
  • 2021-04-01
  • 2021-09-19
  • 2021-08-16
  • 2021-09-19
  • 2021-12-05
  • 2021-12-05
  • 2021-09-19
相关资源
相似解决方案