<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
//原数组
var arr = [0,1,2,3,4,5,6,7,8,9,10,11];
//输出数组
var out = [];
//必须要包含的数字
out.push(2)
//输出个数
var num = 8;
var index = 0;
var run = false;
while(index < num){
var temp = Math.floor((Math.random()*arr.length));
run = false;
for (var i = 0; i < out.length; i++) {
if(out[i] == temp){
run = true;
break;
}
};
if (!run) {
index+=1;
out.push(temp)
};
}
for (var i = 0; i < 100; i++) {
var m = Math.floor(Math.random() * (num - 1));
var n = Math.floor(Math.random() * (num - 1));
if (m != n) {
c = out[n];
out[n] = out[m];
out[m] = c;
}
}
console.log(out)
</script>