function* getIndex(indexList){ var len = indexList.length; var m; while(indexList.length > 0){ m = Math.floor(Math.random()*len+1); var n = indexList.indexOf(m); // console.info(n +" "+indexList); if(n >= 0){ yield m indexList.splice(n,1); } } return m; }
输入一个数组,随机返回数组的元素。