随机抽三个人出来且不重复
<script type="text/javascript">
//选3个人,且不重复
var names = ["严峫", "停停", "蒋丞", "顾飞", "江添"]
var choice = []
for (var i = 1; i <= 3; i++) {
var index1 = Math.round(Math.random() * (names.length - 1 - 0 + 1) + 0)
if (choice.every(function (item, index) {
return item != names[index1]
}) == true && names[index1] != undefined) {
choice.push(names[index1])
} else {
i = i - 1
}
}
console.log(choice)
</script>
输出结果展示
其中主要功能代码同样适用于其他语言环境