web前端|js教程
JavaScript,js,红包
web前端-js教程
本文通过实例代码给大家介绍了基于JavaScript实现微信抢红包功能,金额随机,额度在0.01和(剩余平均值*2)之间,具体的实例代码大家参考下本文
mvc项目源码,vscode设置两个空格,ubuntu无故死机,怎么查看tomcat密码,新药临床 爬虫,php开发需要的工具,山东济南线上营销seo推广,小说采集网站lzw
金额随机:额度在0.01和(剩余平均值*2)之间。
java 官网源码,vscode能换背景图,Ubuntu设置acpi,tomcat源码编译详解,虾爬虫养殖,dicom php,seo新手快速入门实操,dedecms 网站搬迁 模板路径错误lzw
易语言数据库源码,vscode如何更改浏览器,手机ubuntu测评,tomcat四层配置,内鬼和爬虫,php pecl 下载,惠州seo关键词优化服务,个人网站界面模板lzw
/** * 抢红包 * @param {[number]} totalAmount [总金额] * @param {[number]} totalPeople [总人数] * @return {[Array]} [每个人抢到的金额] */function assign(totalAmount, totalPeople){ var remainAmount = +totalAmount; var remainPeople = +totalPeople; var arr = []; while(remainPeople > 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;}
总结