/* 前端写中奖随机数 */ function randomLuckyArr() { Obj.luckyResult = []; for (var i = 0; i < Obj.luckyNum; i++) { var random = Math.floor(Math.random() * personArray.length); if (Obj.luckyResult.indexOf(random) == -1) { Obj.luckyResult.push(random) } else { i--; } } }
这是前端抽奖随机数。你可以从这入手
前端写中奖随机数
我加了历史中奖记录的数组,不刷新页面可以做到去重
function randomLuckyArr() { Obj.luckyResult = []; for (var i = 0; i < Obj.luckyNum; i++) { var random = Math.floor(Math.random() * personArray.length); if (Obj.luckyResult.indexOf(random) == -1 && Obj.luckyResult_history.indexOf(random) == -1) { Obj.luckyResult.push(random) Obj.luckyResult_history.push(random) } else { i--; } } }