金额随机:额度在0.01和(剩余平均值*2)之间。
0){
let num = scramble(remainAmount,remainPeople);
remainAmount = remainAmount - num;
remainPeople--;
arr.push(num);
}
return arr;
}
function scramble(remainAmount,remainPeople){
if(remainPeople === 1){
return +remainAmount.toFixed(2);
}
let max = ((remainAmount / remainPeople) * 2 - 0.01).toFixed(2);
let min = 0.01;
let range = max - min;
let rand = Math.random();
let num = min + Math.round(rand * range); //四舍五入
return num;
}
总结
以上所述是小编给大家介绍的基于基于JavaScript实现微信抢红包功能。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。
原文链接:https://www.f2er.com/js/37719.html